简体   繁体   中英

htaccess url rewrite url containing question mark

I'm having trouble redirecting some urls as below, there are many urls with different cat breeds. Can anyone help with this issue.

Example url to redirect :

http://www.exampledomain.co.uk/cats/database.nsf/catsforsale!openform?Breed=Persian

I want it directing to the url below. My php script should then do some more complex redirect to make the url tidy :

http://www.exampledomain.co.uk/display_pets.php?pettype=Cats&petbreed=Persian

I've tried the rewrite below but it doesnt work, it just doesnt redirect at all, i think it may have something to do with the ? :

RewriteRule ^/cats/database.nsf/catsforsale!openform?Breed=(.*)$ display_pets.php?pettype=Cats&petbreed=$1 [L]

RewriteRule normally does not look at query strings.

You need to use the QSA flag with Rewrite. It combines the query strings and appends it to the target url.

You can try the following:

RewriteRule ^(.*)$ display_pets.php?url=$1 [L]

This will pass the entire source url to the url parameter of the target url. It will also append the query strings of the source url to the target url.

Another option is to match the query string inside RewriteCond.

RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule ^/cats/database.nsf/catsforsale!openform$  display_pets.php?pettype=Cats&petbreed=%1 [L]

See following links:

RewriteRule Flags and Manipulating the Query String

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