.htaccess - 阻止文件从父

时间:2016-10-20 12:05:25

标签: php apache .htaccess redirect mod-rewrite

我的网站结构如下:

include
include/interface/
include/templates/
include/subdomains/

include/subdomains/forum ...

我想在用户查看fodler include及其后的所有子目录时将用户重定向到404错误。这非常有效,子域名将通过官方forums.example.org查看,但不能通过example.org/include/subdomains/forum /

查看

为实现这一点,我使用规则:

Redirect 404 /include/

但是,当我访问论坛并使用论坛中的重写URL时,由于论坛的结构如何,他们会给出错误404。该论坛的结构如下:

包括/ rewrite.php

它试图要求该文件,但由于(我假设的是父.htaccess文件与论坛htaccess文件相关,它不起作用,而且我'得到一个"请求的URL ..可以在这台服务器上找到"错误。

我的问题是,如何让父htaccess文件将网站的include文件夹重定向到错误,而不是论坛的错误?

我的代码如下:

父母htaccess:

RewriteEngine on
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /

ErrorDocument 400 /errors/400
ErrorDocument 401 /errors/401
ErrorDocument 403 /errors/403
ErrorDocument 404 /errors/404
ErrorDocument 500 /errors/500
ErrorDocument 501 /errors/501
ErrorDocument 502 /errors/502
ErrorDocument 503 /errors/503
ErrorDocument 504 /errors/504
ErrorDocument 505 /errors/505
ErrorDocument 506 /errors/506
ErrorDocument 507 /errors/507
ErrorDocument 508 /errors/508
ErrorDocument 509 /errors/509
ErrorDocument 510 /errors/510

AddDefaultCharset UTF-8

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

Redirect 404 include/

论坛htaccess:

# MultiViews INTERFERS WITH PROPER REWRITING.
Options -MultiViews

RewriteEngine On

# UNCOMMENT AND PROPERLY SET THE RewriteBase IF THE REWRITE RULES ARE NOT WORKING PROPERLY.
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . include/rewrite.php [L]

# ----------------------------------------------------------------------
# DISABLE DIRECTORY BROWSING.
# ----------------------------------------------------------------------
<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

# ----------------------------------------------------------------------
# UTF-8 ENCODING.
# ----------------------------------------------------------------------

# USE UTF-8 ENCODING FOR ANYTHING SERVED text/plain OR text/html.
AddDefaultCharset utf-8

# FORCE UTF-8 FOR A NUMBER OF FILE FORMATS.
AddCharset utf-8 .html .css .js .xml .json .rss

# ----------------------------------------------------------------------
# BETTER WEBSITE EXPERIENCE FOR INTERNET EXPLORER USERS.
# ----------------------------------------------------------------------
<IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</IfModule>

<IfModule mod_headers.c>
    # BECAUSE X-UA-Compatible ISN'T SENT TO NON-IE (TO SAVE HEADER BYTES), WE NEED TO INFORM PROXIES THAT CONTENT CHANGES BASED ON UA.
    Header append Vary User-Agent
    # CACHE CONTROL IS SET ONLY IF mod_headers IS ENABLED, SO THAT'S UNNECESSARY TO DECLARE.
</IfModule>

0 个答案:

没有答案