Multiple 404 pages with htaccess

耗尽温柔 提交于 2019-12-25 03:19:46

问题


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

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?


回答1:


You cannot put conditions before ErrorDocument directive.

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]


来源:https://stackoverflow.com/questions/25873530/multiple-404-pages-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!