2013-10-02 41 views
0

我想在.htaccess中設置一些url重寫。.htaccess mod_rewrite規則獨立工作但不在一起

首先是重定向與語言代碼的網址(網站現在是在一種語言):

RewriteRule ^en/(.*)$ /$1 [R=301,L] 
RewriteRule ^es/(.*)$ /$1 [R=301,L] 

===================== ===

二是成爲更具描述性的搜索引擎優化的目的:

/社區/

/導師,和學生/

RewriteCond %{REQUEST_URI} ^.*/community.*$ 
RewriteRule .* /tutors-and-students [L,R=301,DPI] 

=================================

第三個變化曲線網址:

/社區/我的配置文件/用戶名

/導師,和學生/用戶名

RedirectMatch permanent myprofile(.*) http://www.profr.org/tutors-and-students/$1 

=========================

他們都獨立,但沒有一起工作爲:

RewriteRule ^en/(.*)$ /$1 [R=301,L] 
RewriteRule ^es/(.*)$ /$1 [R=301,L] 
RewriteCond %{REQUEST_URI} ^.*/community.*$ 
RewriteRule .* /tutors-and-students [L,R=301,DPI] 
RedirectMatch permanent myprofile(.*) http://www.profr.org/tutors-and-students/$1 

感激你的提示。

+0

當你說沒有工作,你面對的問題是什麼呢? – anubhava

+0

最後的規則沒有做任何事情來重定向URL/myprofile /在這個例子中 – larpo

+0

嘗試使用新的瀏覽器來測試。 – anubhava

回答

0

你應該只用mod_rewrite的堅持,而不是從mod_alias中通過重定向混合在一起的:

RewriteRule ^en/(.*)$ /$1 [R=301,L] 
RewriteRule ^es/(.*)$ /$1 [R=301,L] 

RewriteRule ^.*/?community /tutors-and-students [L,R=301,DPI] 

RewriteRule ^.*/?myprofile(.*)$ /tutors-and-students/$1 [L,R=301] 
+0

嗯 - 這並不完全破解它。網站管理員工具告訴我,我有這樣的404個URL:/ en/community/myprofile/1565-joshua-oganga什麼時候應該重定向到/ tutors-and-students/1565-joshua-oganga。相反,它會去/導師和學生。有什麼想法嗎? – larpo

+0

@larpo您需要翻轉「社區」和「myprofile」規則,因爲社區首先匹配/ en/**社區**/myprofile/1565-joshua-oganga。但我猜你對社區的意義只是**這個網址? '/ EN/community'?然後將社區正則表達式更改爲:'^。* /?community /?$' –

+0

感謝 - 此網址仍然無效 - 它是404 -/community/822-ratna-ventrapragada - 現在的條件是:RewriteRule^en/(。*)$/$ 1 [R = 301,L] RewriteRule^es /(.*)$/ $ 1 [R = 301,L] RewriteRule ^。* /?myprofile(。*)$/tutors-and學生/ $ 1 [L,R = 301] RewriteRule ^。* /?community /?$/tutors-and-students [L,R = 301,DPI] – larpo