I need to permanently redirect requests for a page with query strings to a new page , so that:
http://www.example.com/photos/showimage.php?id=148
or http://www.example.com/photos/showimage.php?id=148&p=5
... will become redirected to:
http://www.example.com/photos/
The "id" parameter will always be requested, though the "p" parameter will only sometimes be requested.
The "id" and "p" values at the end of the query string could be any integer.
I also need to redirect ones like these:
http://www.example.com/photos/showcat.php?category=Exhibition%252BImages%25
... to the same URL:
http://www.example.com/photos/
The value at the end of this query string could be anything.
I've looked at various examples for this type of redirect but they all seem to deal with specific forms that don't work for me.
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=[^&]+ [NC]
RewriteRule ^photos/showimage\.php$ /photos? [L,NC,R=301]
RewriteCond %{QUERY_STRING} (^|&)category=[^&]+ [NC]
RewriteRule ^photos/showcat\.php$ /photos? [L,NC,R=301]
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.