简体   繁体   English

防止对子文件夹使用.htaccess规则

[英]Prevent .htaccess rules to the child folder

Here is my folder structure 这是我的文件夹结构

www.mywebsite.com
www.mywebsite.com/app
www.mywebsite.com/app/firstproject
www.mywebsite.com/app/secondtproject

In the root directory i installed wordpress. 在根目录中,我安装了wordpress。 It allows me to access the www.mywebsite.com/app but when i try to access the www.mywebsite.com/app it is always showing page not found i can guess that it is because of the .htaccess at the root folder. 它允许我访问www.mywebsite.com/app但是当我尝试访问www.mywebsite.com/app它总是显示page not found我可以猜到这是由于根文件夹中的.htaccess

Here is the .htaccess root folder 这是.htaccess根文件夹

# 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

I tried to override the .htaccess to the sub folders by having the below code in the .htaccess of the app folder but it shows the same page not found error. 我试图重写.htaccess由具有在下面的代码到子文件夹.htaccess应用程序文件夹,但它显示了相同的页面没有找到错误。

RewriteRule ^app/ - [L]

How can i access the www.mywebsite.com/app/firstproject without that error ? 我如何才能访问www.mywebsite.com/app/firstproject而不会出现该错误?

Write all rules in the root htaccess file. 将所有规则写入htaccess根文件中。 add RewriteRule ^app/firstproject$ - [L] to prevent rewrite in this path. 添加RewriteRule ^ app / firstproject $-[L]以防止在此路径中进行重写。 For further rewrite within /firstproject, you need conditions and rules similar to web root 要在/ firstproject中进行进一步重写,您需要类似于Web root的条件和规则。

    RewriteEngine On
    RewriteBase /
    RewriteRule ^app/firstproject$ - [L] #add longer path first
    RewriteRule ^index.php$ - [L] #no need to escape \.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
  1. Remove app/.htaccess 删除app/.htaccess
  2. Have this code in root .htaccess: 在根.htaccess中有以下代码:

root .htaccess: 根.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(index\.php$|app/) - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM