htaccess 403无法自定义页面

时间:2014-07-26 19:37:30

标签: .htaccess

我的.htaccess文件:

RewriteEngine On

# If the request sent by the browser includes login1.php...
RewriteCond %{THE_REQUEST} login1\.php
RewriteRule ^ - [F]

RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^ - [F]

ErrorDocument 403 /404.php
ErrorDocument 404 /404.php


# Then you just need a generic rule to rewrite /mysite into login1.php
RewriteRule ^mysite$ login1.php [L]
RewriteRule ^$ index.php [L]

当我尝试访问该页面时:http://example.com/login1.php我收到错误消息:

Forbidden

You don't have permission to access /login1.php on this server.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

但我想在页面404.php

上显示消息

1 个答案:

答案 0 :(得分:0)

您的规则正在循环播放,因为一旦您为/login1.php发出禁止一次,它会继续投掷403,因为%{THE_REQUEST}不会发生变化。

让你的规则解决这个问题:

RewriteRule ^404\.php$ - [L,NC]

# If the request sent by the browser includes login1.php...
RewriteCond %{THE_REQUEST} (index|login1)\.php
RewriteRule ^ - [F]

ErrorDocument 403 /404.php
ErrorDocument 404 /404.php

# Then you just need a generic rule to rewrite /mysite into login1.php
RewriteRule ^mysite$ login1.php [L]
RewriteRule ^$ index.php [L]