带有htaccess的多个404页 [英] Multiple 404 pages with htaccess
本文介绍了带有htaccess的多个404页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个htaccess,它可以检查IP,然后将用户重定向到适当的页面.现在,我正在使用ErrorDocument 404/404.php,但我想基于IP创建单独的404页.如果我把它放在..
I have a htaccess that checks the IP and then redirects the user to the appropriate page. Right now I'm using ErrorDocument 404 /404.php but I want to have seperate 404 pages based on the IP. If I place that under the..
RewriteCond %{REMOTE_ADDR} x.x.x.x
规则,它仍然转到相同的404页.我如何像其他页面一样为404页面帐户添加IP地址?
rule it still goes to the same 404 page. How do I make the 404 page account for the IP like the rest of the pages do?
推荐答案
您不能在ErrorDocument
指令之前放置条件.
You cannot put conditions before ErrorDocument
directive.
作为解决方法,您可以使用mod_rewrite
为您处理这种情况:
As a workaround you can use mod_rewrite
to handle this situation for you:
RewriteEngine On
# handle 404 for IP=x.x.x.x
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REMOTE_ADDR} =x.x.x.x
RewriteRule . /ip1-404.php [L]
# handle 404 for IP=y.y.y.y
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REMOTE_ADDR} =y.y.y.y
RewriteRule . /ip2-404.php [L]
这篇关于带有htaccess的多个404页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文