tags:

views:

16

answers:

2

I would like to rewrite dynamic URL

/index.php?pid=login&redirect=/previous-page.html

to something like this

/login.html-r-previous-page.html

I tried this

RewriteRule ^login.html-r-(.*)$ /index.php?pid=login&redirect=$1 [L]

But no succes. I was also trying to change the regex to .+ or some other forms, but it seems useless. Maybe I am making mistake somewhere else.

I am new to regular expressions and also mod_rewrite.

Thank you for help

+1  A: 

You have to escape the dot character and you should escape the backreference since it's to become part of the query string. You were also inconsistent in that the regex pattern match had the assumption there was a rewrite base (there's no / in the beginning) and the new path add a / in the beggining. You also forgot to a add a / in the beginning of the redirect parameter

RewriteEngine on
RewriteBase /
RewriteRule ^login\.html-r-(.*)$ index.php?pid=login&redirect=/$1 [L,B]
Artefacto
A: 

This is a quick answer, most likely wrong but:

RewriteRule ^/login\.html\-r\-(.*)$ /index.php?pid=login&redirect=$1 [L]

I think regex is mad about the "." and the "-" since they are special... Also maybe the forward slash at the beginning will help, maybe not, try it with and without

Also i would check the flags (at the end in the []) to make sure they are right

Bob Fincheimer