我想使用.htaccess
将http://www.yourdomain.com/page.php?或http://www.yourdomain.com/page.php?var=val重定向到404错误页面。
我已使用此代码
RewriteRule ^page\.php\?.*$ /404.shtml [R=404,L]
但它没有用。
答案 0 :(得分:1)
您无法从RewriteRule指令获取查询字符串。
如果要检测var=val
或?
(空查询字符串),请使用
#if query string has var=val
RewriteCond %{QUERY_STRING} var=val [NC,OR]
#or it just has ? with no query string
RewriteCond %{THE_REQUEST} page\.php\?\ [NC]
#and resource is page.php serve 404
RewriteRule ^page\.php$ /404.shtml [R=404,L,NC]