Can't get my Simple rewrite to work

We changed the software/script on my site.

The pages and links are different, we do still use the same id’s, here is the real-world example:

Old script:
http://www.mysite.com/photos/details.php?cat_id=750&image_id=53974
http://www.mysite.com/photos/categories.php?cat_id=750

New script:
http://www.mysite.com/album.php?yr=2009&aid=0750

The only thing that is important here is the old “cat_id”, which is now “aid”, the number is the same (750 in this case) but since we’re now using 4 digits, there needs to be an extra 0 for this, which I added. However, I can’t get it to work…
I’ve placed this in the root (/) of my site.
The old script had 2 different pages, a details page and a categories page, both had the cat_id. The image_id from the details.php can be ignored, this can be redirected to the new album.php with the “aid”.

Can anyone spot my fault(s) ?


RewriteEngine On
Options +FollowSymLinks 
Redirect ^photos/categories\\.php\\?cat_id=([0-9]+)$ http://www.mysite.com/album.php?yr=2009&aid=0$1

ThanQ Everyone !

I also did:
RewriteRule ^photos/categories.php?cat_id=([0-9]+)$ http://www.mysite.com/album.php?yr=2009&aid=0$1

No Luck…

cb,

Back to the tutorial, my friend! I don’t believe Redirect(Match) can examine the query string just like a RewriteRule can’t (it can only attempt to match the {REQUEST_URI} string). THEREFORE, you MUST use RewriteCond to examine (and capture) from the query string for your redirects.

If you can’t get the answer you need from those hints, come back and I’ll lead you through it (I don’t code for free but am willing to spend the time to help members LEARN about mod_rewrite).

Regards,

DK

No luck yet…

RewriteCond %{QUERY_STRING} !marker  
RewriteCond %{QUERY_STRING} aid=([-a-zA-Z0-9_+]+)  
RewriteRule ^/?album\\.php$ %1? [R=301,L]  
 
RewriteRule ^/?photos/categories\\.php\\?cat_id=([-a-zA-Z0-9_+]+)$ http://www.partypixsuriname.com/album.php?yr=2009&aid=0$1 [L]

cb,

I don’t understand your use of the !marker test. What’s that for?

No matter, it shouldn’t play a part (unless ‘marker’ is in your query string).

THEN, what’s with trying to redirect album.php to the value of aid? that will NOT work (unless aid is a filename in your DocumentRoot)!

FINALLY, you fall back on trying to test/capture a value in a query string using a RewriteRule. That will NEVER work (as explained above, a RewriteRule can ONLY examine the {REQUEST_URI} string which, by definition, does NOT include the {QUERY_STRING}). You have the correct approach in your RewriteCond statements in the first mod_rewrite block; why did you abandon that? Do the same thing in the second mod_rewrite block BUT do not use the full absolute URL, only the URI (or the redirection will be displayed - if you WANT it displayed, use R=301 so SEs know it’s a permanent redirection).

Regards,

DK