【问题标题】:URL rewriting whilst using codeigniter使用 codeigniter 时的 URL 重写
【发布时间】:2011-06-14 19:24:40
【问题描述】:

我正在使用以下内容在 codeigniter 中删除我的 index.php -

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L] 

我正在用我用 codeigniter 编写的新网站替换旧网站,因此我需要将一些旧网址重写为新网址。这对于单页来说效果很好,但是我遇到了以下重写的问题-

RedirectMatch 301 ^/comments/(.*)/$ /location/$1 

理论上,这应该将您重定向到: http://www.mysite.com/comments/123http://www.mysite.com/location/123

因为我正在通过重写删除 index.php,所以我最终会被定向到 -

http://www.mysite.com/location/123?/comments/123/

有谁知道如何解决这个问题?

谢谢。

【问题讨论】:

    标签: .htaccess mod-rewrite codeigniter url-rewriting


    【解决方案1】:

    终于搞定了,有兴趣的我只好在第一篇文章中没提到的rewrite条件中加了cmets:

    RewriteCond $1 !^(index\.php|media|images|css|js|comments|robots\.txt)

    希望这可能对其他人有所帮助。

    【讨论】:

      【解决方案2】:

      您不应混合使用 mod_alias (RedirectMatch) 和 mod_rewrite。试试这个 mod_rewrite 规则:

      RewriteRule ^comments/(.*)/$ /location/$1 [L,R=301]
      

      现在只需确保将此规则放在其他规则之前。

      【讨论】:

      • 谢谢,我不擅长 URL 重写。认为我不应该将两者混为一谈,但这是我能找到让它发挥作用的唯一方法。
      猜你喜欢
      • 1970-01-01
      • 2020-06-03
      • 2014-01-10
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多