Rewrite domain.com/file.php?var=2 to domain.com/new/url/

Discuss practical ways rearrange URLs using mod_rewrite.

Rewrite domain.com/file.php?var=2 to domain.com/new/url/

Postby DarkPepe » Mon Nov 03, 2008 1:27 pm

Hi, I need some help to move some old content from my portal to another url.

Im using

www.domain.com/file.php?var=2 (wich does not exists anymore) I need to create a redirection to www.domain.com/somenew/url/


I also need the same for ?var=1 nd ?var=3 to poing to anothernew/url and yetanothernew/url

Any help will be apreciated.

Thank you.
DarkPepe
 
Posts: 11
Joined: Thu Dec 14, 2006 11:25 pm

Postby richardk » Mon Nov 03, 2008 3:13 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Match the query string variable.
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
# Match the file and redirect to the new URL.
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DarkPepe » Mon Nov 03, 2008 3:47 pm

richardk wrote:Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Match the query string variable.
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
# Match the file and redirect to the new URL.
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]


Very nice, thank you.

I ran into another problem, var=x works redirecting to somenew/url/, but var=x&anothervar=y still redirects to somenew/url when Im using your code:


Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Match the query string variable.
RewriteCond %{QUERY_STRING} ^(.*&)?var=x$anothervar=y(&.*)?$ [NC]
# Match the file and redirect to the new URL.
RewriteRule ^file\.php$ /different/url/? [NC,R=301,L]



Any way to tweak it?

Thank you very much again.
DarkPepe
 
Posts: 11
Joined: Thu Dec 14, 2006 11:25 pm

Postby richardk » Tue Nov 04, 2008 10:22 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Two variables (with var=2).
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?another=variable(&.*)?$ [NC]
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]

# One variable (var=2).
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby DarkPepe » Tue Nov 04, 2008 12:12 pm

richardk wrote:Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Two variables (with var=2).
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?another=variable(&.*)?$ [NC]
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]

# One variable (var=2).
RewriteCond %{QUERY_STRING} ^(.*&)?var=2(&.*)?$ [NC]
RewriteRule ^file\.php$ /somenew/url/? [NC,R=301,L]



Excelent! that works like a charm.. thanks a lot again!
DarkPepe
 
Posts: 11
Joined: Thu Dec 14, 2006 11:25 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests

cron