问题
My Folder Structure
- Root Domain
- assets/ (contains css, images, js folders)
- subfolder/ (contains Codeigniter Project inside and seperate .htaccess)
- index.php
- contact.php
- .htaccess
Root Htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)subfolder
RewriteRule ^(.*)$ subfolder/$1 [L]
Subfolder(Codeigniter Project) Htaccess
DirectoryIndex index.php index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|install|update)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For godady Shared Hosting Server uncomment the line below
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
List of Subfolder URLs
- http://example.com/subfolder/products/
- http://example.com/subfolder/product/product-slug-123
List of Root URLs
- http://example.com/index.php
- http://example.com/contact.php
In my Codeigniter Project I've set Products
controller as default_controller
.
So the problem is, when I try to access the index.php page in the Root folder it only displays the Codeigniter products list as Home page.
I need following URLs:
- http://example.com/index.php
- http://example.com/contact.php
- http://example.com/products/
- http://example.com/product/product-slug-123
Any solutions with htaccess or with code?
回答1:
Finally I got this working.
RewriteCond %{REQUEST_URI} !((.*)subfolder|^/assets) // to Exclude this
RewriteCond %{REQUEST_URI} (^/products(.*)|^/product(.*)) // to Include this
RewriteRule ^(.*)$ subfolder/$1 [L]
Exclamation(!) symbol used to 'not' matching urls.
So I removed Exclamation symbol and used another RewriteCond (Condition) to redirect only if url contains segment as products
or product
http://example.com/products/ or http://example.com/product/product-slug-123. So Its working perfectly. I thought it would be useful to someone. Happy coding.
来源:https://stackoverflow.com/questions/57992993/remove-subfoldercodeigniter-only-for-specified-urls-using-htaccess