![](/img/trans.png)
[英]Remove subfolder from url using only php code and not with help of .htaccess
[英]Remove Subfolder[Codeigniter] only for specified URLs using Htaccess
我的文件夾結構
根訪問
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)subfolder
RewriteRule ^(.*)$ subfolder/$1 [L]
子文件夾(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>
子文件夾 URL 列表
根 URL 列表
在我的 Codeigniter 項目中,我將Products
控制器設置為default_controller
。 所以問題是,當我嘗試訪問 Root 文件夾中的 index.php 頁面時,它只將 Codeigniter 產品列表顯示為主頁。
我需要以下網址:
任何使用 htaccess 或代碼的解決方案?
最后我得到了這個工作。
RewriteCond %{REQUEST_URI} !((.*)subfolder|^/assets) // to Exclude this
RewriteCond %{REQUEST_URI} (^/products(.*)|^/product(.*)) // to Include this
RewriteRule ^(.*)$ subfolder/$1 [L]
感嘆號(!)符號用於“不”匹配網址。
因此,我刪除了感嘆號並使用另一個 RewriteCond(條件)僅在 url 包含細分為products
或product
http://example.com/products/或http://example.com/product/product-slug-123 時重定向. 它現在工作得很好。 我想,分享這對某人有用。 快樂編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.