问题
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