使用Htaccess仅针对指定的URL删除Subfolder [Codeigniter] [英] Remove Subfolder[Codeigniter] only for specified URLs using Htaccess

查看:53
本文介绍了使用Htaccess仅针对指定的URL删除Subfolder [Codeigniter]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹结构

  • 根域
    • 资产/(包含css,图像,js文件夹)
    • subfolder/(在内部包含Codeigniter项目,并单独使用.htaccess)
    • index.php
    • contact.php
    • .htaccess
    • Root Domain
      • assets/ (contains css, images, js folders)
      • subfolder/ (contains Codeigniter Project inside and seperate .htaccess)
      • index.php
      • contact.php
      • .htaccess

      root 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列表

      • http://example.com/subfolder/products/
      • http://example.com/subfolder/product/product-slug-123

      根URL列表

      • http://example.com/index.php
      • http://example.com/contact.php

      在我的Codeigniter项目中,我已将Products控制器设置为default_controller. 所以问题是,当我尝试访问Root文件夹中的index.php页面时,它仅将Codeigniter产品列表显示为主页.

      In my Codeigniter Project I've set Products controller as 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.

      我需要以下URL:

      • http://example.com/index.php
      • http://example.com/contact.php
      • http://example.com/products/
      • http://example.com/product/product-slug-123

      任何使用htaccess或代码的解决方案?

      Any solutions with htaccess or with code?

      推荐答案

      最后,我成功了.

      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.

      因此,我删除了感叹号,并仅在URL包含段为productsproduct的情况下,才使用另一个RewriteCond(条件)进行重定向 http://example.com/product/product-slug-123 .因此,它的工作完美.我认为这对某人有用.编码愉快.

      So I removed Exclamation symbol and used another RewriteCond (Condition) to redirect only if url contains segment as products or product http://example.com/products/ or http://example.com/product/product-slug-123. So Its working perfectly. I thought it would be useful to someone. Happy coding.

      这篇关于使用Htaccess仅针对指定的URL删除Subfolder [Codeigniter]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆