猿问

仅使用 Htaccess 删除指定 URL 的子文件夹 [Codeigniter]

我的文件夹结构

  • 根域

    • assets/ (包含 css, images, js 文件夹)

    • 子文件夹/(包含内部的 Codeigniter 项目和单独的 .htaccess)

    • 索引.php

    • 联系人.php

    • .htaccess

根 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. 所以问题是,当我尝试访问根文件夹中的 index.php 页面时,它只将 Codeigniter 产品列表显示为主页。

我需要以下网址:

任何带有 htaccess 或代码的解决方案?


慕码人2483693
浏览 162回答 1
1回答

ITMISS

最后我得到了这个工作。RewriteCond %{REQUEST_URI} !((.*)subfolder|^/assets) // to Exclude thisRewriteCond %{REQUEST_URI} (^/products(.*)|^/product(.*)) // to Include thisRewriteRule ^(.*)$ subfolder/$1 [L]感叹号(!)符号用于“不”匹配的网址。所以我删除了感叹号并使用另一个 RewriteCond (条件)仅当 url 包含段 asproducts或product http://example.com/products/或http://example.com/product/product-slug-123时才重定向。它现在工作得很好。我想,分享这个对某人有用。快乐编码。
随时随地看视频慕课网APP
我要回答