Forum Moderators: phranque
Basically I want to redirect www.example.com/keyword/index.html to www.example.com/keyword.html. I understand that for this to happen I need to do two things. First I would need the rewrite conditions in htaccess file and then I would have to set up a 301 redirect to the index.html pages so that someone visiting them directly gets redirected to keyword.html pages. I have tried various combinations of rewrite and redirect statements but haven't been able to figure out the correct ones. Can someone help?
RewriteRule ^([a-zA-Z0-9+]*).html $1/index.html
It works for the keyword subcategories but gives a 404 error on homepage of the website by effectively redirecting it to "/index/index.html"
I am already redirecting the "/index.html" to "/" for the homepage. Can it be the reason? Any ideas how I can get around this?
# Redirect non-standard incoming domains to standard
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=permanent]
# Redirect client index.html requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
# Redirect category pages to old ones
RewriteRule ^([a-zA-Z0-9+]*).html $1/index.html
#
My website has several hundred pages whose urls changed recently from www.example.com/categorykeyword.html to www.example.com/categorykeyword/index.html due to a change in cms. I am trying to get a redirect and rewrite in place so that the old links are still valid and the new ones are simply 301'd.
With the last line in htaccess file above I managed to get the category rewrite working but it is also redirecting www.example.com/index.html (homepage) to www.example.com/index/index.html, which of course does not exist.
# Redirect client index.html requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.[b]html[/b]\ HTTP/
RewriteRule ^index\.[b]php[/b]$ http://www.example.com/ [R=301,L]
# Redirect category pages to old ones
RewriteRule ^([a-zA-Z0-9+]*).html $1/index.html
# Externally redirect client index.html URL requests to "/" URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]
#
# Internally rewrite new category page URLs to old cat page filepaths
RewriteCond $1 !^index$
RewriteRule ^([a-z0-9+]*)\.html $1/index.html [NC,L]
Jim
What have you changed in the code?
What were your test cases and results?
What were the results of those tests?
How did those results differ from your expectations and requirements?
It is very difficult to help without a solid understanding of what you are trying to accomplish.
Thanks,
Jim
My website had the following convention for urls for individual categories (there are about 500 of them)
OLD URL - http://www.example.com/categoryname.html
After a recent update in the CMS I was using, it changed to
NEW URL - http://www.example.com/categoryname/index.html
Predictably this tanked my google rankings and I have been trying to fix this with htaccess.
I figured out I need to do two things here.
First I need to rewrite the new url to old one. Second I need to redirect (301). As I am a newbie in htaccess and apache, I searched for some similar examples on net and in this forum and tried to fix it, but was unsuccessful.
In one of the psots by jdMorgan above, it was suggested that I use the following:
# Externally redirect client index.html URL requests to "/" URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]
#
# Internally rewrite new category page URLs to old cat page filepaths
RewriteCond $1!^index$
RewriteRule ^([a-z0-9+]*)\.html $1/index.html [NC,L]
It worked well to fix the first problem i.e. rewriting the new url for the old url.
Now I have two identical pages at both the locations (old url and new url).
To avoid duplicate penalties, I need to somehow redirect the new url to old url i.e.
http://www.example.com/categoryname/index.html >>somehow 301 to>> http://www.example.com/categoryname.html
As there are a large number of categories and somehow the CMS does not work if I edit the hard coded links inside it, I am left with htaccess as the only option I can use. I hope it is a bit more clear now. I am sorry for my hasty questions before.
Thanks in advance.
There's no good way to fix this unless you change the links published on your pages.
That said, the following code will do the redirect you describe:
RewriteRule ^([^/]+)/index\.html$ http://www.example.com/$1.html [R=301,L]
If this were my site, I'd be looking into modifying the CMS to prevent it from changing the URLs in the first place. If that's not at all possible, then I'd be 301-redirecting the old URLs to the new ones -- not the other way 'round. IOW, accept the fact that if I use that CMS, I'll have to live with the new URLs, and be done with it. A temporary short-term drop in search rankings is better than returning a 301 for every search engine request for your linked URLs in perpetuity.
Jim