【问题标题】:Codeigniter 301 redirection index.phpCodeigniter 301 重定向 index.php
【发布时间】:2013-06-25 07:50:06
【问题描述】:

我想在codeigniter中删除index.php后做301重定向。

htaccess 文件:

RewriteEngine on

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

在这之后我添加了

RewriteRule /index.php?page=9-someting&txt=12 /page/1/someting#2/other [R=301,L]

但是重定向没有任何帮助?

编辑:

/index.php?page=9-someting&txt=12 不是CodeIgniter写的老网站

【问题讨论】:

    标签: php codeigniter .htaccess redirect


    【解决方案1】:

    将您的第二个更特殊的规则移到通常 CI 的 nice url 的 catch-all-and-send-to-index 规则之前。您可能还想添加NE(因为没有编码),因为否则哈希标记(#)将被编码。

    所以是这样的:

    RewriteEngine on
    # rewrite old site url, has L so processig will stop here for matching requests.
    RewriteCond %{QUERY_STRING} ^page=9-someting&txt=12$
    RewriteRule index.php /page/1/someting#2/other [R=301,L,NE]
    
    
    # request that fall trouhg will be sent to CI's front controller (if they are not images, css....)
    RewriteCond $1 !^(index\.php|images|css|img|js|plugins|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 不起作用,如果我放除 index.php 以外的任何东西,一切正常。
    • 抱歉,我刚刚意识到您正在尝试匹配 RewriteRule 行中的查询字符串参数。这在那里行不通,你必须使用RewriteCond,因为RewriteRules 匹配请求的url-path。
    • 这行得通,但是否有可能在 url 重定向之后不是:mysite.com/page/1/someting#2/other?index.php?page=9-someting&txt=12跨度>
    • 这不应该发生,这些重写不应该与当前 URL 相关,我不确定那里发生了什么。
    • Chrome 显示“此网页有重定向循环”?
    【解决方案2】:

    在.htaccess试试这个

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L,R=301]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,R=301]
    </IfModule>
    
    RewriteRule ^index.php?page=9-someting&txt=12$ /page/1/someting#2/other [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 2010-10-27
      相关资源
      最近更新 更多