I am using .htaccess code for 301 redirection my subdomain to domain. And also using domain.php?id=123
and need to redirect it into the domain name. My codes are below.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://www.domain.com/dom.php?id=12$
RewriteRule (.*) http://www.domain.com/ [R=301,L]
But when I trying to do this, i got an error like, it redirect to http://www.domain.com/?id=12
page
You cannot match REQUEST_URI
and QUERY_STRING
using RewriteCond %{HTTP_HOST}
, try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^dom\.php$ /? [R=301,L,NC]
This will redirect http://www.domain.com/dom.php?id=12
to http://www.domain.com/
.
Or to redirect any http://www.domain.com/dom.php?id=<number>
:
RewriteCond %{QUERY_STRING} ^id=\d+$
RewriteRule ^dom\.php$ /? [R=301,L,NC]
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.