簡體   English   中英

僅使用 Htaccess 刪除指定 URL 的子文件夾 [Codeigniter]

[英]Remove Subfolder[Codeigniter] only for specified URLs using Htaccess

我的文件夾結構

  • 根域
    • assets/(包含css、images、js文件夾)
    • 子文件夾/(包含 Codeigniter 項目和單獨的 .htaccess)
    • 索引.php
    • 聯系方式
    • .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 包含細分為productsproduct http://example.com/products/http://example.com/product/product-slug-123 時重定向. 它現在工作得很好。 我想,分享這對某人有用。 快樂編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM