简体   繁体   中英

htaccess url redirect (character “?”)

I have a url like this:

 http://mydomain.es/foro.php?topic=9

And I want to redirect it to:

 http://mydomain.es/foro/9/

But I can't get it to work, I have tried something like:

 redirectMatch  302 ^/foro.php\?topic=([0-9]+)$ /foro/$1/

But it don't work, the problem is the character ?, if i remove it in the url (and use a redirectMarch like

 redirectMatch  302 ^/foro.phptopic=([0-9]+)$ /foro/$1/) 

it works fine, can you help me? I'm going crazy.

answered here - query strings are not supported by rewritematch. Use mod_rewrite instead.

This should work :

 RewriteEngine On
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?foro\.php\?topic=([^&\s]+) [NC]
 RewriteRule ^ /foro/%1? [NE,NC,R,L]

RewriteRule ^([^/]+)/([^/]+)/?$ /foro.php?topic=$2 [QSA,NC,L]

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