2012-07-24 157 views
1

客戶端有一個表達式引擎網站,並且希望刪除'index.php'。單單這樣做會在他的網站SEO排名中產生影響,因爲它會改變所有網址。因此,我們希望通過在所有網頁中添加301來保留鏈接公平和社交網絡分享次數。刪除index.php並在.htaccess(ExpressionEngine)中添加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] 

回答

2

您只希望如果實際要求是一個/index.php/ URL重定向。您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(可以通過第二個規則得到重寫)相匹配。

+0

完整意義。萬分感謝。如果我最終有一個變量會怎麼樣? '/ feature/article/{variable_article_name} /' 我該如何將請求中的{variable_article_name}「移動」到重寫中? – 2012-07-24 03:48:32

+0

@RyanDunlap err,再次編輯答案。 – 2012-07-24 03:55:52

+0

現在我們在說話!很棒。感謝您的洞察力。 – 2012-07-24 04:26:55