简体   繁体   中英

.htaccess RewriteRule - matching patterns & forwarding posts

I'm trying to write a rule that maintains legacy urls with a rule that matches a pattern but I would like to add something that redirects url posts as well. I'm not good a this htaccess stuff. Here is a scenario:

Legacy URL:

www.blah.com/register/player

Legacy RewriteRule:

RewriteRule ^register/(.*)/?$ /account/register.php?type=$1 [NC,L]

New URL:

www.blah.com/register/player?email=bob@g.com

New RewriteRule???

RewriteRule ^register/(.*)/?$ /account/register.php?type=$1 [NC,P]

I found this post Is it possible to redirect post data? that helped me find the P flag which works without the pattern match but it doesn't work when I try to do both.

I don't want to just add another pattern match because my url post data can be arbitrary with more then one param (the case described above is simplified). It seems like this should be doable. Is it? Thanks.

Seems like you need the query string attached on redirect, hence the QSA flag

Try:

RewriteRule ^register/(.*)/?$ /account/register.php?type=$1 [QSA,NC,P]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM