Cant figure it out

New to mod_rewrite? This is a good place to start.

Cant figure it out

Postby machine11 » Thu Sep 10, 2009 6:04 am

Hey Guys, I cant figure out a simple expression.

I simply want to rewrite and redirect permanently a few old urls to new ones.
I dont even mind going through all of them manually

one example
www.domain.com/engravable-cufflinks/cat_11.html?page=1
to http://www.domain.com/engravable-cuffli ... 11-p2.html

I thought this was the command:
RewriteRule ^engravable-cufflinks/cat_11.html?page=1 http://www.domain.com/engravable-cuffli ... 11-p2.html [NC,R=301,L]

but it doesnt seem to be working - am I missing something?

thanks!
Alain
machine11
 
Posts: 7
Joined: Sat Dec 22, 2007 6:42 am

Postby richardk » Thu Sep 10, 2009 7:46 am

Query strings are matched with RewriteConds and the %{QUERY_STRING} variable.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?page=1(&.*)?$ [NC]
RewriteRule ^engravable-cufflinks/cat_11\.html$ http://www.domain.com/engravable-cufflinks/cat_11-p2.html? [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks

Postby machine11 » Thu Sep 10, 2009 8:16 am

Big thank you, worked first time, now I need to apply to about 100 urls.
thanks! :)
Alain
machine11
 
Posts: 7
Joined: Sat Dec 22, 2007 6:42 am

Postby richardk » Thu Sep 10, 2009 2:28 pm

Is there a pattern in the URLs?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

pattern

Postby machine11 » Thu Sep 10, 2009 2:37 pm

Actually yes, it was all the same pattern :) -- page=1, page=2, etc...

this is really helping in the site move :)
thanks!
machine11
 
Posts: 7
Joined: Sat Dec 22, 2007 6:42 am

Postby richardk » Thu Sep 10, 2009 2:59 pm

If it was page=1 to -p1 you could use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?page=([0-9]+)(&.*)?$ [NC]
RewriteRule ^engravable-cufflinks/cat_11\.html$ http://www.domain.com/engravable-cufflinks/cat_11-p%2.html? [NC,R=301,L]

but that doesn't look like it's the case. Where would page=2 redirect to?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

page=2

Postby machine11 » Thu Sep 10, 2009 3:05 pm

machine11
 
Posts: 7
Joined: Sat Dec 22, 2007 6:42 am

Postby richardk » Sat Sep 12, 2009 2:54 pm

Then i don't think there is a general rule that can be written.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 27 guests

cron