【问题标题】:Using mod_rewrite to redirect old urls with Codeigniter使用 mod_rewrite 通过 Codeigniter 重定向旧 url
【发布时间】:2012-05-15 01:55:03
【问题描述】:

我正在使用 codeigniter 框架重新开发一个网站。

当我们上线时,我们希望确保将一些旧网址重定向到新网站上的相应页面。

所以我将我认为正确的规则放入现有的 htaccess 文件中,置于 CodeIgniter 应用的其他规则之上。

但是,它们没有生效。谁能建议我在这里缺少什么?

# pickup links pointing to the old site structure
RewriteRule ^(faq|contact)\.php$ /info/ [R=301]
RewriteRule ^registration\.php$ /register/ [R=301]
RewriteRule ^update_details\.php$ /change/ [R=301]

# Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^_system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# This snippet prevents user access to the application folder
# Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^myapp.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# This snippet re-routes everything through index.php, unless
# it's being sent to resources
RewriteCond $1 !^(index\.php|resources)
RewriteRule ^(.*)$ index.php/$1 

【问题讨论】:

    标签: codeigniter mod-rewrite url-rewriting


    【解决方案1】:

    尝试将 [L]ast 标志添加到您的 R=301 标志 => [L,R=301] 以确保没有应用其他规则,并且,为了确定,尝试重定向到完整的 URL 并,为了更加确定您没有删除任何内容,请将 RewriteEngine On 添加到顶部并设置 RewriteBase。

    让你的第一行看起来像

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(faq|contact)\.php$ http://www.YOURDOMAIN.XYZ/info/ [L,R=301]
    

    并检查当您调用常见问题页面时浏览器中的 URL 是否发生变化。

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 2012-11-12
      • 1970-01-01
      • 2012-02-22
      • 2014-04-01
      • 2010-11-09
      • 2015-09-14
      • 2023-03-18
      相关资源
      最近更新 更多