简体   繁体   中英

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. 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.

Here is the .htaccess root folder

# 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.

RewriteRule ^app/ - [L]

How can i access the www.mywebsite.com/app/firstproject without that error ?

Write all rules in the root htaccess file. add RewriteRule ^app/firstproject$ - [L] to prevent rewrite in this path. For further rewrite within /firstproject, you need conditions and rules similar to 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
  2. Have this code in root .htaccess:

root .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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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