简体   繁体   中英

How do I redirect a url with parameters

How do I redirect a url with parameters I will like to write this url:

http://mydomain.com/dk/silkeborg?latitude=56.1631229&longitude=9.536976500000037&zoom=14

and redirect it to

http://mydomain.com/index.php?country=dk&city=silkeborg&latitude=56.1631229&longitude=9.536976500000037&zoom=14

To day I use the below rule, that don't take any parameters

RewriteRule (dk|de)/(.*)  index.php?country=$1&city=$2 [NC]

Please help me

You do need to use [QSA] because you're rewriting the query (it's enabled by default unless you rewrite the query). Here we're capturing the country code and passing it as a var. Then QSA is catching the rest of the variables and adding them to the query string.

RewriteCond %{REQUEST_URI} ^/(dk|de)/ [NC]
RewriteRule .* index.php?country=%1 [QSA,L]

To use your existing rule, you would append [QSA]

RewriteRule (dk|de)/(.*)  index.php?country=$1&city=$2 [QSA,NC,L]

When the page loads you can access the country via $_GET['country'] and city via $_GET['city'] .

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