2014-03-31 34 views
0

我想重寫URL的一個部分像一個給定域:的.htaccess,重寫URL的一部分特定領域

www.example.com/.* - >www.example.com/sub/.*

即改寫www.example.comwww.example.com/sub,同時保持其他部分的路徑。

我已經嘗試了許多方法了幾個小時,這是一個最有前途的,到目前爲止,但仍然不成功:

RewriteEngine On 
RewriteBase/
RewriteRule ^www.example.com/(.*)$ http://www.example.com/sub/$1 [R=301,L] 

任何想法是錯誤的一個以上或其他建議?

回答

0

試試這個:

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^(www\.)?example.com 
RewriteCond %{REQUEST_URI} !^/sub 
RewriteRule^http://www.example.com/sub%{REQUEST_URI} [R=301,L] 

其自帶RewriteRule語法請求URI不是HTTP主機相匹配後的圖案。因此,例如www.example.com/hello部分hello將用於模式匹配。

#Start with hello do your stuff 
RewriteRule ^hello target_url [Flags] 
+0

我明白了。完美的作品。非常感謝。 – LordBarrington