0

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

2 Answers 2

1

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]
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.