Php Mod rewrite将文件夹重定向到根目录并将文件夹用作根目录

Php Mod rewrite将文件夹重定向到根目录并将文件夹用作根目录,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我已将mi站点文件移动到子文件夹,并使用.htaccess重定向到该子文件夹,但我需要拒绝对此文件夹或子文件夹的直接访问 在.htaccess中获取了以下内容: <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteR

我已将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>
在site/live中存在另一个。htaccess具有一些重写规则。这可能是问题所在吗

<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

重写规则^about us$about.php
重写规则^privacy$privacy.php
重写规则^oauth$index.php
DirectoryIndex.php
#自定义错误消息/页面
ErrorDocument 404/404.php
ErrorDocument 403/403.php

/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>
DirectoryIndex.php
#自定义错误消息/页面
ErrorDocument 404/404.php
ErrorDocument 403/403.php
重新启动发动机
#从URL中删除/site/
RewriteCond%{THE_REQUEST}/site/(\S+)[NC]
重写规则^/%1[L,R=302,NE]
重写规则^about us$about.php
重写规则^privacy$privacy.php
重写规则^oauth$index.php

/site/live/
是否有另一个.htaccess?@anubhava是的,我已经用更多的细节更新了这个问题hanks@anubhava,几乎成功了。我必须从
RewriteRule^/%1[L,R=302,NE]
中删除%1,因为它被重定向到/live witch not existence(404)。我的意思是live的规则不存在,尽管目录存在,但我需要从
http://domain.com
。现在它重定向
http://domain.com/site/live
http://domain.com
没关系。
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>