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
-
cross canonicalization with redirect
I'm working with a website that has turned one of its pages into its own website within the main website - mostly for the ease of customers, making it simpler to access that page using www.page.com rather than www.mainsite.com/about/page.
Technical SEO | | Shrine.SEO.Gal
As a result, there are two urls for that page (the ones just mentioned), both pointing to the exact same page, but with different urls. Now, they have made it so www.mainsite.com/about/page permanently redirects to www.page.com. which I thought was a good call. However, what do I do about canonicalization? Is it good to point the canonicalization of www.page.com to www.mainsite.com/about/page so that the rankings and link equity are maintained in the main website? Or would the fact that the www.mainsite.com/about/page redirects to www.page.com mess that up? I hope this makes sense!0 -
WPEngine Causing Redirect Chain
Hi guys, Had a quick question that I wanted to verify here. After reviewing a Moz report we received some redirect chain error on all of our sites hosted with WPEngine. We noticed that the redirect chain appears to be coming from how the domains are configured in their control panel. Essentially, there is a redirect: from staging/temp -> to live from non-www -> to www SSL redirect from http -> https The issue here is that the non-www is redirecting to www and then redirected again to https://www According to support the only way to get rid of this error is to drop the www version of the domain and to host everything under https://domain.com. To me it seems very odd that you cannot just go from http://non-www to https://www in just 1 301 redirect. Has anyone else experienced this or am I just not looking at the situation correctly?
Technical SEO | | AaronHenry0 -
Mobile website question
Hi Mozzers, A website I manage has a mobile friendly version of their main website and a /m version as well. I was wondering if anyone had any experience in the best way of handling this? Should we just get rid of the /m version and tag the mobile friendly version? Thanks!
Technical SEO | | KarlBantleman0 -
Which to redirect to, www or non-www?
Please help. I have a client who's site has duplicate content issues due mainly to the www/non-www problem. The MOZ page authority of both is the same, the www version has more linking root domains, and for most of the keywords the www version shows up in Google. The developer indicated the site is on the non-www. I need to do a .htacess 301 redirect to eliminate the dup content problems. Which do I redirect to? Any help is greatly appreciated, Thanks!!
Technical SEO | | SteveFaber0 -
The Ultimate Question
This is probably going to look bad, but Im going to do it anyway. Ive owned my own business for over twenty five years. Due to the economy and a health crisis, my business has come to an end. Im left pretty much with nothing except my family, which is on shakey grounds as well. anyway. Ive been working on the IM, SEO thing for about two years. Ive made some money, but nothing that would make a difference to my situation. I now have a site in a competitive niche. The site is rated A by the app here on seomoz. But my site is lacking in authority backlinks. I write my own posts, about two a day, and honestly, it is of much better quality than those ranking . My site stays right around #11. Every other day, the site goes to #7 or 8. When that happens, I make between 300-400 a day. Then it falls back to 11. So the on site is good, rated A here. My site is speedy Not enough backlinks The content is good I was foolish enough to believe the G story about backlinks not being important. Concentrate on the content. All of that crapola. The sites that are ranking well have all the typical xrumer links. Totally not related links. Junk. And from what Ive seen, I believe the sites ranking 1-3 are making about $1000. a day. So you can imagine what being this close, after losing so much is doing to me. So.... Right now I am just writing content, pinging, social bookmarking and submitting rss feeds daily. Does anyone have any real information on how to bump my site up in rankings. Please, no stories about guest blogging, or attempts to sell me your SEO service I know I would do it for someone else and I have many times in the past. If you can help me, please reread, and contact me. I wish you all the best. Sorry for the melodrama.
Technical SEO | | vansy0 -
Domain redirection and seo implications
We have an existing site that is a subdomain but we recently acquired an exact match domain. Will building links to the exact match domain and having the domain point at our existing subdomain work or should we convert the entire site and redirect our existing subdomain to the new domain? What I'm trying to figure out is how to maximize the benefit here and how the existing mass of links pointing to our existing subdomain (shop.domain.com) can be used. New domain: keywordshop.com Existing URL: shop.domain.com
Technical SEO | | CHarkins0 -
How long should I keep 301 redirects?
I have modified a the URL structure of a whole section of a website and used mod_rewrite 301 redirect to match the new structure. Now that was around 3 months ago and I was wondering how long should I keep this redirect for? As it is a new website I am quite sure that there are no links around with the old URL structure but still I can see the google bot trying from time to time to access the old URL structure. Shouldn't the google bot learn from this 301 redirect and not go anymore for the old URL?
Technical SEO | | socialtowards0 -
Wordpress 301 redirects
I use wordpress as CMS on a few sites and I noticed that word press automattically places 301s if I change a url etc. I believe it does it by having the following in the .htaccess file: BEGIN WordPress<ifmodule mod_rewrite.c="">RewriteEngine OnRewriteBase /RewriteRule ^index.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</ifmodule> END WordPress Should I use this? I feel like it limits my control over the 301s.
Technical SEO | | mmaes0