Forum Moderators: phranque
I manage the 301 redirect from non-www to www in .htaccess:
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301,L]
I manage the 301 redirect from non-index.html to index.html (example [mysite.com...] to [mysite.com...] in realurl (TYPO3 module).
Is there a better way to accomplish the above? I can't drop /index.html as I have to many external links to my internal pages. Is it possible and does it make sense to manage the 301 from / to /index.html, on internal pages only, in .htaccess? If so, what is the correct htaccess code for manage the following kind of redirect?
[mysite.com...] redirect to [mysite.com...] (homepage non-www to www)
"http://mysite.com/../<page>/index.html", "http://mysite.com/../<page>/" and "http://mysite.com/../<page>" (without slash) all redirect to "http://www.mysite.com/../<page>/index.html" (non-www internal pages, with or without index.html, redirect all to www with index.html)
Use of "index.html" (or .htm or .php or .asp) is both unnecessary and wasteful. It also makes your links look ugly in the search results, dilutes any keyword-in-URL benefits, and dissuades people from trying to type-in your URLs. It effectively lays a trap for you in that it makes a future technology upgrade very difficult: What if you want to switch your site to .php or .asp some day?
If you want to pursue this, try searching WebmasterWorld for "redirect index rewritecond the_request [google.com]" to find many previous threads.
Jim
Use of "index.html" (or .htm or .php or .asp) is both unnecessary and wasteful.
I agree. However dropping 'index.html' has a cost. Our urls ( /index.html ) are indexed correctly by all the major search engines, we enjoy a high keyword rank and have several thousand external links. So the most appropriate solution is to resolve the multiple redirect.
Per tedster's recommendation I have reviewed your thread [webmasterworld.com]. I have also reviewed [webmasterworld.com...] But I am still unsure which of the following is the correct code for my specific case, i.e.:
redirect 301 for my non-www homepage
http://example.com or http://example.com/ to http://www.example.com/
redirect 301 for non-www and non-index.html URLs (with or without the trailing slash) to index.html for
example:
http://example.com/category to http://www.example.com/category/index.html
http://example.com/category/ to http://www.example.com/category/index.html
http://example.com/category/index.html to http://www.example.com/category/index.html
http://example.com/category/page to http://www.example.com/category/page/index.html
http://example.com/category/page/ to http://www.example.com/category/page/index.html
http://example.com/category/page/index.html to http://www.example.com/category/page/index.html
http://example.com/category/subcategory/page to http://www.example.com/category/subcategory/page/index.html
http://example.com/category/subcategory/page/ to http://www.example.com/category/subcategory/page/index.html
http://example.com/category/subcategory/page/index.html to http://www.example.com/category/subcategory/page/index.html
This question was asked and answered less than 18 hours ago; check the threads around this one.
Thanks g1smd, I read the thread [webmasterworld.com] prior to posting and while it deals with a subfolder it doesn't address redirects from / to /index.html. In other words how to redirect urls with nothing after the trailing slash.
[edited by: jdMorgan at 3:53 pm (utc) on Jan. 23, 2009]
[edit reason] Please use example.com [/edit]
RewriteRule, with a pattern that ends /$ will select out URLs that end with a "/" for redirecting, but I must caution that search engines usually "prefer" to list the shorter (ending with "/") URL. What are you doing about URLs that end with a foldername and no trailing slash? Usual practise is to redirect to add the slash back on. In this case it could result in a double redirect, from /folder to /folder/ to /folder/index.html. If you also have non-www to www redirect rules, then some requests could see a triple redirect.
By using /folder/ as the target, it is possible to redirect from all of the non-canonical forms, such that a request for any non-canonical form is redirected to the correct form, in just one hop.