繁体   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