【问题标题】:editing .htaccess file编辑 .htaccess 文件
【发布时间】:2010-10-09 03:46:20
【问题描述】:

我使用 CodeIgniter 制作了一个应用程序,并尝试使用CodeIgniter User Guide 中列出的 apache mod_rewrite 规则,如下所示:

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

问题是我在文件夹abc/ 中有这个应用程序,但是当我输入mysite/abc/something(应该指向mysite/abc/index.php/something)时,我被重定向到mysite/index.php/something。

我应该对.htaccess 文件进行哪些更改才能使其正常工作?

【问题讨论】:

    标签: .htaccess mod-rewrite codeigniter


    【解决方案1】:
    RewriteCond $1 !(index\.php|^images|^robots\.txt)
    RewriteRule (.*) index.php/$1 [L,NS]
    

    【讨论】:

    • 您是不是忘记了^ 还是那样?此外,[L,NS] 是做什么的?
    • 我删除了 RewriteCond 上的初始 ^,以便它会忽略您网站中的任何 index.php,而不仅仅是 /index.php(^index.php 将不匹配 /abc/index.php;它位于子目录中的 .htaccess 中不会使路径相对于该子目录)。规则中的 ^ 和 $ 无关紧要。
    • NS 抑制子请求的规则。当规则触发时,会生成一个以 index.php/whatever 作为 URL 的子请求; NS 阻止规则查看子请求。 RewriteCond 的 index.php 检查也应该防止它被重写,所以它有点像腰带和吊带。
    【解决方案2】:

    尝试在替换中使用相对路径:

    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 2019-11-28
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      相关资源
      最近更新 更多