Codeigniter:301重定向来自旧网站的URL

时间:2015-01-22 16:15:25

标签: php .htaccess codeigniter redirect http-status-code-301

我最近推出了一个codeigniter网站,需要从旧网站到新网站进行301重定向。他们不会使用正则表达式,所以,因为只有少数几个,我可以为每个页面编写重定向。然而,经过数小时的谷歌搜索/纠正,我仍然没有快乐。旧网站的网址是.html文件,而我的codeigniter网址是" clean"网址。这是我当前的.htaccess文件:

<IfModule mod_alias.c>
   redirect 301 "/index.html" /index.php
</IfModule>

<IfModule mod_rewrite.c>
    DirectoryIndex index.php
    RewriteEngine on

    #This is the redirect I've been trying to make work
    RewriteRule ^/about-us.html /index.php?/about-us [R=301,L]

    RewriteCond $1 !^(index\.php|index\.html|lib|robots\.txt)
    RewriteRule ^(.*)$ index.php?/$1 

</IfModule>

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteRule ^(about-us)\.html$ /index.php?/$1 [R=301,NC,L,QSA]

或重定向所有旧的.html链接:

RewriteRule ^(.+?)\.html$ /index.php?/$1 [R=301,NC,L,QSA]

编辑:根据评论,您只需要此规则来处理旧网址:

RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]