Redirecting Dynamic URLs

Discuss practical ways rearrange URLs using mod_rewrite.

Redirecting Dynamic URLs

Postby zerokarma » Thu Jan 25, 2007 12:51 pm

I am in the process of upgrading a site, a photo album in particular and would like to redirect the old dynamic urls to the new location but I can't seem to get a mod_rewrite rule to work.

OLD URL examples:
http://www.zerokarma.com/modules.php?na ... s&album=13
http://www.zerokarma.com/modules.php?na ... ls&album=9
http://www.zerokarma.com/modules.php?na ... s&album=15

NEW URL examples:
http://www.zerokarma.com/photoalbum/thumbnails-13.html
http://www.zerokarma.com/photoalbum/thumbnails-9.html
http://www.zerokarma.com/photoalbum/thumbnails-15.html

Anyone know exactly how I can write a rule that will redirect those old dynamic urls to the newer ones. The new urls are already active so I just need to forward/redirect the old ones to it somehow.
zerokarma
 
Posts: 2
Joined: Thu Jan 25, 2007 12:42 pm
Location: Toronto, Canada

Postby zerokarma » Thu Jan 25, 2007 2:51 pm

Nevermind, I figured it out after searching Google for a while.

This code appears to work for me in my case:

Code: Select all
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /modules\.php\?name=([^&]+)&file=([^&]+)&album=([^&]+)\ HTTP/
rewriteRule ^modules\.php$ http://www.zerokarma.com/photoalbum/thumbnails-(%3).html? [R=301,L]
zerokarma
 
Posts: 2
Joined: Thu Jan 25, 2007 12:42 pm
Location: Toronto, Canada

Postby richardk » Fri Jan 26, 2007 10:14 am

I'd do it like this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

Rewritecond %{QUERY_STRING} ^(.*&)?name=photo_album(&.*)?$ [NC]
Rewritecond %{QUERY_STRING} ^(.*&)?file=thumbnails(&.*)?$  [NC]
Rewritecond %{QUERY_STRING} ^(.*&)?album=([0-9]+)(&.*)?$   [NC]
RewriteRule ^modules\.php$ http://www.zerokarma.com/photoalbum/thumbnails-%2.html? [NC,R=301,L]

Then variable order will not matter.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 9 guests

cron