...

View Full Version : Redirect old url to new url by cuting some word



DooDoo
01-25-2011, 09:07 AM
I just change all url in my website around 2000 url.

The pattern of old url have fix pattern such as www.example.com/book-XXXXXXXX.html

where book- is fix and XXXXXXXX is variable.

I change the new url by delete fixing word book-.

so www.example.com/book-XXXXXXXX.html is changed to www.example.com/XXXXXXXX.html

Anyone please kindly advise how to write in .htaccess to redirect all old url to new url.

I have try 2 times as follows but it does not work.


RewriteCond http://www.example.com/book-^(.*)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


RewriteCond http://www.example.com/book-(.*) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Many thanks in advance.

abduraooft
01-25-2011, 09:17 AM
Try
RewriteRule ^book\-(.*)$ /$1 [R=301,L] without any RewriteCond

css-quest
01-25-2011, 09:17 AM
I tried doing a 301, too but it resulted in not being able to access my site at all. I'd like the 301 to make the old files redirect to the new ones.

Inigoesdr
01-25-2011, 06:05 PM
Did you remove the RewriteCond like abduraooft suggested? Your original RewriteCond is missing the variable to test against. See the example in the top-right of the mod_rewrite cheat sheet (http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/).

DooDoo
01-26-2011, 03:54 AM
Did you remove the RewriteCond like abduraooft suggested? Your original RewriteCond is missing the variable to test against. See the example in the top-right of the mod_rewrite cheat sheet (http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/).

Yes, I did and it work now. A little problem is some url that have book-book-XXXXX.html will have double redirect.

I am very new on mod-rewrite , if you have any more suggestion please kindly advise.

RewriteCond , It has many variable, which one should I use it ?

%{REQUEST_FILENAME} or any one.

abduraooft
01-26-2011, 08:53 AM
A little problem is some url that have book-book-XXXXX.html will have double redirect.

RewriteRule ^(book\-)+(.*)$ /$2 [R=301,L]?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum