2013-10-04 26 views
1

我有一個網站與wordpress有博客頁面。htaccess的RewriteRule更改無內容的網址

所以,現在這個網頁的網址就像http://abc.com/blog

,但我想這個URL轉換爲http://blog.abc.com

我在.htaccess文件中加入代碼,但重寫無法正常工作。重寫模式也在Apache中。

任何人有想法如何改變這個網址?

我想首先在我的本地wamp中測試,所以如果可能的話,請給本地主機提供建議。

代碼是,我試圖

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^abc\.com/blog [NC] 
RewriteRule http://blog.abc [R=301,L] 
+0

如果喬恩的答案適合你,那麼不要忘記標記爲接受。 – anubhava

回答

0

你的規則需要看起來像:

RewriteCond %{HTTP_HOST} ^abc\.com$ [NC] 
RewriteRule ^blog/(.*)$ http://blog.abc.com/$1 [R=301,L] 

%{HTTP_HOST}變量只有主機名,沒有路徑信息是它的一部分(例如/blog)。 RewriteRule需要至少2個參數:

RewriteRule <pattern to match against the URI> <if matched, rewrite/redirect to this URL> <flags>