Here's my folder structure:
{root}/pages/page1/index.php {root}/pages/page2/index.php {root}/pages/page3/index.php
Here's what I'm trying to accomplish:
When I go to {root}/page1
, it checks the /pages
subdirectory to see if there is a matching folder name, then it loads that folder. If not, it 404's. I would want this set with a wildcard so I wouldn't have to add it manually.
At the main root directory .htaccess
file put the following code :
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/pages/page1/
RewriteRule ^page1/(.*)$ /pages/page1/$1 [L]
If you want a code to work with all in pages directory change it to this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pages/(.*)/
RewriteRule ^(.*)/(.*)$ /pages/$1/$2 [L]
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.