【问题标题】:.htaccess rewrite with codeigniter.htaccess 用 codeigniter 重写
【发布时间】:2014-02-26 19:34:41
【问题描述】:

我有一个 codeigniter 设置,其中所有 URL 都重定向到 index.php,如下所示。

我需要 /api/index.php 去 /api,但不是通过重定向。

我下面的代码与 api/index.php 匹配,但仍然无法正常工作。

/index.php/api 工作正常,并转到正确的 URL,但是 /api/index.php 只是转到 404 错误页面......有什么建议吗?我是不是很傻?

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

【问题讨论】:

  • 标题具有误导性。我称之为rewrite 而不是redirect。它们完全不同。
  • 仅使用 'L,QSA' 而不是 L。也可能您可以尝试在 uri 上添加转义斜杠。

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

可能是因为它正在寻找一个名为 /api/index.php 的文件

添加这些重写条件

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
//Your rewrite rule here

【讨论】:

    【解决方案2】:

    试试这个:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|img|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 1970-01-01
      相关资源
      最近更新 更多