[英]Remove Subfolder[Codeigniter] only for specified URLs using Htaccess
My Folder Structure我的文件夹结构
Root Htaccess根访问
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)subfolder
RewriteRule ^(.*)$ subfolder/$1 [L]
Subfolder(Codeigniter Project) Htaccess子文件夹(Codeigniter 项目)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子文件夹 URL 列表
List of Root URLs根 URL 列表
In my Codeigniter Project I've set Products
controller as default_controller
.在我的 Codeigniter 项目中,我将Products
控制器设置为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.所以问题是,当我尝试访问 Root 文件夹中的 index.php 页面时,它只将 Codeigniter 产品列表显示为主页。
I need following URLs:我需要以下网址:
Any solutions with htaccess or with code?任何使用 htaccess 或代码的解决方案?
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 the url contains segment as products
or product
http://example.com/products/ or http://example.com/product/product-slug-123 .因此,我删除了感叹号并使用另一个 RewriteCond(条件)仅在 url 包含细分为products
或product
http://example.com/products/或http://example.com/product/product-slug-123 时重定向. It's working perfectly now.它现在工作得很好。 I thought, sharing this would be useful to someone.我想,分享这对某人有用。 Happy coding.快乐编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.