【问题标题】:301 redirect in codeignitercodeigniter 中的 301 重定向
【发布时间】:2009-12-30 12:30:30
【问题描述】:

好的,所以我不知道这是服务器问题还是什么。我有一个像这样的 htaccess 文件:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/main/index/$1 [L]
RewriteRule ^ajax/(.*)$ /index.php?/main/ajax/$1 [L]
RewriteRule ^backend.php/(.*)$ /backend.php?/$1 [L]

# 301 redirects
Redirect 301 /backup.php http://www.example.com/backup/
Redirect 301 /document.php http://www.example.com/document/
Redirect 301 /contact.php http://www.example.com/contact/
Redirect 301 /links.php http://www.example.com/links/
Redirect 301 /jobs.php http://www.example.com/jobs/

我唯一的问题是我的 301 重定向。而不是

example.com/backup.php 转到 example.com/backup/ 而是将其发送到 example.com/backup/?/main/index/backup.php。

这确实可以正确路由页面。这意味着我得到了正确的 html 返回,但 url 很丑。我应该说这是在代码点火器中完成的,并且我将一切都路由到 main 控制器的方法 index 这使得备份、文档、联系人等成为 index 方法的第一个参数。这可能看起来很奇怪 - 也可能没有相关性 - 但我需要它是这样的。有人对如何清理重定向的 url 有任何建议吗?

【问题讨论】:

    标签: php .htaccess codeigniter redirect


    【解决方案1】:

    同时使用 mod_alias 和 mod_rewrite 不是一个好主意。试试这个 mod_rewrite 规则而不是你的 Redirect 指令并将它放在你当前的规则前面:

    RewriteRule ^(backup|document|contact|links|jobs)\.php$ http://www.example.com/$1/ [L,R=301]
    

    【讨论】:

    • 有趣...实际上将 /backup.php 路由到 /backup.php 导致 404 错误。 :(还有其他想法吗?
    • @ocergynohtna:你真的把这条规则作为你规则集中的第一条规则吗?
    • 我把它放在我原来有 301 的底部,将它移到顶部解决了这个问题。谢谢秋葵!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 2013-01-09
    • 2018-12-26
    • 1970-01-01
    • 2018-08-06
    相关资源
    最近更新 更多