将一个主页重写为404而不是其他主页

时间:2015-03-16 12:58:36

标签: apache .htaccess mod-rewrite url-rewriting

我有以下三条重写规则,根据用户的工作情况将用户引导至付款方式:

RewriteRule ^/marketing/staff$ https://www.example.com/marketing/payroll/forms/salary-payment-form.shtml?stafftype=EXAMPLE [R,L]

RewriteRule ^/marketing/other-staff$ https://www.example.com/marketing/payroll/forms/salary-payment-form.shtml?stafftype=HR [R,L]

RewriteRule ^/marketing/other2-staff$  https://www.example.com/marketing/payroll/forms/salary-payment-form.shtml?stafftype=EXAMPLE\ Commercial\ Ltd [R,L]

我想提出一个规则,以便如果有人只是转到主网址,他们就会获得404 - 我尝试添加下面的网址,但它不起作用:

RewriteCond %{REQUEST_URI} ^/marketing/payroll/forms/salary-payment-form.shtml$
RewriteRule ^/marketing/payroll/forms/salary-payment-form.shtml$ - [R=404,L]

当我把它放在上面所有的网址中都得到404时 - 如何限制它以便上面的主网址只给出404而不是重定向到特定网页的网址?

1 个答案:

答案 0 :(得分:1)

试试这个(%{QUERY_STRING}不属于%{REQUEST_URI}):

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/marketing/payroll/forms/salary-payment-form.shtml$ - [R=404,L]