删除index.php并在.htaccess(ExpressionEngine)中添加301重定向

时间:2012-07-24 03:29:52

标签: php .htaccess mod-rewrite expressionengine

客户端有一个表达式引擎网站,并希望删除'index.php'。单独这样做将削弱他的网站SEO排名,因为它将改变所有URL。因此,我们希望通过向所有页面添加301来保留链接权益和社交网络共享计数。

我知道如何删除index.php并且我知道如何重定向(我认为),但是当我同时使用它们时,服务器会抛出重定向循环。我的逻辑被扭曲了。我在这里缺少什么?

以下是我正在使用的内容:

# Redirect attempt
Redirect 301 /index.php/feature/article/ http://domain.com/feature/article/

# EE index.php rewrite
RewriteCond $1 !^(index\.php|js|path\.php|press_releases|rear|robots\.txt|text\.html|themes) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L] 

1 个答案:

答案 0 :(得分:2)

如果实际请求适用于/index.php/网址,您只想重定向。将您的Redirect指令更改为:

# Redirect attempt
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^/?index.php/feature/article/(.*)$ http://domain.com/feature/article/$1 [R=301,L]

此条件与服务器获取的实际请求相匹配,而不是URI(可由第二条规则重写)。

相关问题