我已经将mi网站文件移动到子文件夹并使用.htaccess重定向到它,但我需要拒绝直接访问此文件夹或子文件夹。
在.htaccess中得到了这个:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Block access to hidden files and directories.
# This includes directories used by version control systems such as Git and SVN.
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
# Deny direct access to this directory or any sub-directory
RewriteRule ^site/(.*)$ / [R=301,NC,L]
# Do not apply redirection to these folders/files for compatibility
RewriteRule ^(subdir1|subdir2)(/|$) - [L,NC]
RewriteRule ^robots.txt - [L,NC]
# root from sub-directory
RewriteRule ^(.*)$ site/live/$1 [L,QSA]
</IfModule>
当我去:
htt://domain.com/site -> htt://domain.com (CORRECT REDIRECTING)
htt://domain.com/site/unexist-> htt://domain.com (CORRECT REDIRECTING)
htt://domain.com/site/live -> htt://domain.com/site/live/ (NOT REDIRECTING HERE!)
在site / live中存在另一个.htaccess 和一些RewriteRule。这可能是问题吗?
<IfModule mod_rewrite.c>
RewriteRule ^about-us$ about.php
RewriteRule ^privacy$ privacy.php
RewriteRule ^oauth$ index.php
</IfModule>
DirectoryIndex index.php
# Custom error messages / pages
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
答案 0 :(得分:0)
在/site/live/.htaccess
中使用此代码:
DirectoryIndex index.php
# Custom error messages / pages
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
<IfModule mod_rewrite.c>
RewriteEngine On
# remove /site/ from URL
RewriteCond %{THE_REQUEST} /site/(\S+) [NC]
RewriteRule ^ /%1 [L,R=302,NE]
RewriteRule ^about-us$ about.php
RewriteRule ^privacy$ privacy.php
RewriteRule ^oauth$ index.php
</IfModule>