.htaccess编辑允许URL

时间:2013-08-08 17:06:46

标签: html .htaccess web

通过CPanel中的IP拒绝管理器,将正确的代码行添加到根目录中的.htaccess文件中。

但我不喜欢默认的403错误。我宁愿让它显示一个图像,这样我就可以自定义这个错误的外观和消息,并提供给被拒绝的访问者。

我添加了ErrorDocument行,其中包含指向我正在使用的html文件的链接。这就是我的wordpress网站的设置方式。

订单允许,否认 允许所有人

ErrorDocument 403 http://www.mydomain.com/403.htm

[IP here] [IP在这里] 等...

添加此行后,它会尝试提供页面,但看起来有一个重定向循环,因为所有文件都被拒绝,它无法提供此页面。由于我想在.htm页面中使用图像,我认为除非它是从我网站之外的其他网址提供的,否则也会被阻止。

有没有办法添加一些代码以允许这些被阻止的IP只能访问这两个URL路径?一个用于根目录下的403.htm页面,另一个用于我在该页面中使用的.jpg,它也将存储在root中?

我认为这可以解决我的问题并允许我将此页面和图形提供给被拒绝的IP。

提前致谢!

2 个答案:

答案 0 :(得分:0)

将您的ErrorDocument指令设为/.htaccess

ErrorDocument 403 /403.htm

尝试使用

进行访问
<FilesMatch "403\.(htm|jpg)$">
  order allow, deny
  allow from all
</FilesMatch>

将您的html和图像文件命名为403(或您可能喜欢的任何其他内容)。

答案 1 :(得分:0)

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    </IfModule>

    # END WordPress

    ErrorDocument 403 /403.htm
    <FilesMatch "403\.(htm|jpg)$">
    order allow,deny
    allow from all
    </FilesMatch>

    deny from [several IP's here]