重定向到404错误页面哪个网址包含“page.php?”

时间:2012-01-03 20:03:57

标签: .htaccess

我想使用.htaccesshttp://www.yourdomain.com/page.php?http://www.yourdomain.com/page.php?var=val重定向到404错误页面。

我已使用此代码

RewriteRule ^page\.php\?.*$ /404.shtml [R=404,L]

但它没有用。

1 个答案:

答案 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]