0

我在 htaccess 中遇到了这个问题。我使用 CodeIgniter 并从链接中删除了“index.php”:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(robots\.txt|sitemap\.xml)

RewriteRule ^(.*)$ /index.php/$1 [L]

这很好用。

但是现在,我有一个旧的网站,上面有这样的旧链接:

http://www.example.com/index.php/about_us/article/70,about-us

它们被谷歌索引。我想将它们重定向到新的链接结构。

我需要更改 htaccess,所以上面的链接重定向到如下所示的链接:

http://www.example.com/en/about_us/70,about-us

' index.php ' 被删除,没关系。“文章”并不总是显示在链接中,只是在一些链接中,但它始终是一个片段。而且我必须在前面添加'en'(lang)。

我怎样才能做到这一点?

4

2 回答 2

0

试试这些;

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(robots\.txt|sitemap\.xml)
RewriteRule ^en/(.*)$ /index.php/$1 [L]

路由.php

$route["about_us/(:any)"] = "about_us/article/$1";

有关 url 路由的更多信息: URI 路由

于 2013-05-16T08:46:45.470 回答
0

这应该让你接近(未经测试,只是为你拼凑在一起)。您可能需要调整第一条规则以检查该en段是否存在,因为如果存在,您最终会在重定向的 URL 中出现双精度数。

RewriteEngine On

# Redirect any URI's starting with "index.php" to new URI
RewriteRule ^index.php/(.*)$ http://www.example.com/en/$1 [R=301,L]

# Route URI's to index.php front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
于 2013-05-17T22:12:05.527 回答