views:

88

answers:

1

So have rewritten my ugly php URL to something prettier:

RewriteEngine On
RewriteRule ^main/photo([^/\.]+)/?.html$ main/details.php?gid=$2pid=$1

However, now I want to force anyone who goes to

http://www.example.com/main/details.php?gid=20&pid=5

to redirect to

htto://www.example.com/main/photo5.html

I have tried the following RewriteCond:

RewriteCond %{REQUEST_URI} ^/main/details\.php [NC]
RewriteRule ^main/details.php?gid=(.*)&pid=(.*) http://www.example.com/main/photo$1.html [R=301,L]

But that didn't work. Any ideas?

A: 

You need to look into the request line to determine if the current request URI is the original. Additionally you need to use the RewriteCond directive to test the query of the URI:

RewriteCond %{THE_REQUEST} ^GET\ /main/details\.php
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pid=([0-9]+)(&.*)?$
RewriteRule ^main/details\.php$ /main/photo%3.html? [L,R=301]
Gumbo
I get send to photo.html?pid=5.
Lenni
@Lenni: FIxed it.
Gumbo
Lenni
EDIT: Found it, you will need to change %1 to %3.
Lenni