Redirect question
-
I would like to redirect http://example.com/index.html to http://www.example.com/
Is the code below correct ?
RewriteEngine on
RewriteCond %{HTTP_HOST}^example.comRewriteRule (.*)
http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
RewriteRule ^index.html$ http://www.example.com/ [R=301,L]
-
I would go with the code the way Rasmus has laid it out for you. I will check out the tool and let youknow.
-
Many Many Thanks Robert for the useful link.
I tried the tool but it didn't generated the code as stated above. Have i missed something ?
-
Thanks Rasmus Olesan.
-
Atul, I think the way Rasmus has it here is correct. The other day I came across a tool for 301's that will write for you. FULL Disclosure is I have not used it yet. If you want to check it out, the site is
http://seo-website-designer.com/HtAccess-301-Redirect-Generator
Might be worth a try.
-
The first portion of your code seems correct, although the line breaks are a bit off in the post? We have a similar approach for forwarding non-www to www-pages.
RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I've google a bit and found the following code:
All in all, I would say your .htaccess code should be:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.)$ http://www.domain.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^./index.html
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]Best way to get an answer? Try uploading the .htaccess code and see if it works - if not, take it down again and correct the code. However the above should work I should think.
-Rasmus
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Redirects Advice
We have many redirects in place - and sometimes 2 in a chain. Is there a recommended time you should have a redirect in place?
Technical SEO | | Caroline_Ardmoor0 -
Sub Domain Redirect
Hey Everyone, Here is the situation : Currently, a website's sub domain is being redirected to the main website home page. We're having issues getting the sub domain pages indexed. Just want to confirm that it is because of the redirect on the sub domain URL. Should we kill the sub domain redirect and set it up as it's own page? Will that solve the indexing issue for the sub domain pages. More explanation below: subdomain.domain.com currently redirects to domain.com We're having issues indexing pages belonging to the sub domain ( subdomain.url.com/page1 or subdomain.url.com/page2) Appreciate your input in advance. Cheers,
Technical SEO | | SEO5Team0 -
.htaccess Redirect 301 issues
I have completely rewritten my web site, adding structure to the file directories. Subsequently added was Redirect information within the .htaccess file. The following example ...
Technical SEO | | Cyberace
Redirect 301 /armaflex.html http://www.just-insulation.com/002-brands/armaflex.html
Returns this response in the URL bar of ...
http://www.just-insulation.com/002-brands/armaflex.html?file=armaflex
I am at a loss to understand why the suffix "?file=armaflex" is added The following code is inserted at the top of the file ...
RewriteEngine On redirect html pages to the root domain RewriteRule ^index.html$ / [NC,R,L] Force www. prefix in URLs and redirect non-www to www RewriteCond %{http_host} ^just-insulation.com [NC]
RewriteRule ^(.*)$ http://www.just-insulation.com/ [R=301,NC] Any advice would be most welcome.0 -
Redirect to get better ranking
I have three pages of my website ranking for a keyword: landing page and two blogposts. They all rank on top of page 2 (positions 11-13).If I redirect these articles to the landing page, will it help to bring it up in rankings?
Technical SEO | | imoney0 -
What to do with 302 redirects being indexed
Hi there, Our site's forums include permalinks that for some reason uses an intermediary URL that 302 redirects to the URL with the permalink anchor. For example: http://en.tradimo.com/learn/chart-analysis/time-frames/ In the comments, there is a permalink to the following URL; en.tradimo.com/co/50c450005f2b949e3200001b/ (there is no content here, and never has been). This URL 302 redirects to the following final URL: http://en.tradimo.com/learn/chart-analysis/time-frames/?offset=0&limit=20#50c450005f2b949e3200001b The problem is, Google is indexing the redirect URL (en.tradimo.com/co/50c450005f2b949e3200001b/) and showing duplicate content even though we are using the nofollow tag on these links. Ideally, we would directly use the last link rather than redirecting. Alternatively, I'd say a 301 redirect would be preferable. But if both aren't available, is there a way to get these pages out of the index? Is the canonical tag the best way? I really wish I could just add /co/ to the robots.txt file, but I think they would still be in the index, right? Thanks for your help!
Technical SEO | | etruvian0 -
Popup Question
Hi Everyone, I have a question. Your input will be very much appreciated. My company's new website design is using a popup. I have some reservation about it and I want to know what your thoughts are. Ok, some information on what this popup is like. When a user clicks on a subcategory page, there's a popup that would ask for size, color, etc - it's like a form and those are the criteria. If nothing is selected, the product list on the subcategory page doesn't load - so the only thing is showing is the the H1 and description but everything else is empty. When a user does select a criteria the landing page is no longer the subcategory but another page with that ID. So basically the user never really land on the subcategory page but to another page with a different query string. Is this bad for SEO? Would you recommend to keep the popup? Thanks,
Technical SEO | | truckguy770 -
301 Redirects Not Allowed by Host
Not sure if anyone has an answer, but we have a client who has an ecommerce store with SBI! The client has a new site with a new store builder/host and wants to 301 redirect all of the old site's indexed pages to the new site. However, we were just informed by SBI! that 301 redirects are not allowed - even more, they don't even grant FTP access. Any brilliant ideas from anyone how we can get around this?? Thank you!
Technical SEO | | roundabout0 -
301 redirects twice
We currently have some 301 redirects set up on our site however sometimes a page will redirect twice before reaching the final location. Is this OK from an SEO perspective to have a page redirect twice or should we concentrate on reducing it to one?
Technical SEO | | JohnHillman0