简体   繁体   中英

htaccess 301 redirect with ? (question mark) in URL not working

This is probably a simple question, but I can not find why the 301 with an ? in the URL is not working. I have done a 301 redirect in the .htacces file but it´s not working. Other 301-redirects are working except for the one with a question mark in the URL.

I want http://www.example.com/?forum=2115543 redirected to http://www.example.com but the simple standard 301-redirect doesn´t work.

Example in .htaccess: Redirect 301 /?forum=2115543 /

You can not match a query string with Redirect (mod_alias) . You need to use mod_rewrite .

You can give this a try.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^forum=(.+) [NC]
RewriteRule ^ /? [R=301,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