代码点火器:来自旧站点的 301 个重定向 URL


Codeigniter: 301 redirect URLs from old site

我最近推出了一个代码点火器网站,需要从旧网站重定向到新网站进行一些 301 重定向。它们不会与正则表达式一起使用,因此,由于只有少数几个,我可以为每个页面编写重定向。然而,经过几个小时的谷歌搜索/纠正,我仍然没有快乐。旧站点的 URL 是.html文件,而我的代码点火器 URL 是"干净"的 URL。这是我当前的 .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>

有什么想法吗?

您可以使用:

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

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

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

编辑:根据注释,您只需要此规则来处理旧URL:

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