Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2011, 09:07 AM   PM User | #1
DooDoo
New to the CF scene

 
Join Date: Jan 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
DooDoo is an unknown quantity at this point
Redirect old url to new url by cuting some word

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.

Quote:
RewriteCond http://www.example.com/book-^(.*)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Quote:
RewriteCond http://www.example.com/book-(.*) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Many thanks in advance.
DooDoo is offline   Reply With Quote
Old 01-25-2011, 09:17 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Try
Code:
RewriteRule ^book\-(.*)$ /$1 [R=301,L]
without any RewriteCond
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
DooDoo (01-26-2011)
Old 01-25-2011, 09:17 AM   PM User | #3
css-quest
New Coder

 
Join Date: Nov 2010
Posts: 42
Thanks: 7
Thanked 0 Times in 0 Posts
css-quest is an unknown quantity at this point
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.
css-quest is offline   Reply With Quote
Old 01-25-2011, 06:05 PM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 01-26-2011, 03:54 AM   PM User | #5
DooDoo
New to the CF scene

 
Join Date: Jan 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
DooDoo is an unknown quantity at this point
Quote:
Originally Posted by Inigoesdr View Post
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.
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.
DooDoo is offline   Reply With Quote
Old 01-26-2011, 08:53 AM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
A little problem is some url that have book-book-XXXXX.html will have double redirect.
Code:
RewriteRule ^(book\-)+(.*)$ /$2 [R=301,L]
?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:08 PM.


Advertisement
Log in to turn off these ads.