2012-07-12 30 views
0

我有一個WordPress的多站點實例,由於某種原因,默認爲domain.com(/ blog,前面沒有www。前面帶www的任何請求都會被強制轉到主頁(domain.com/blog)而不是它的我想要做的就是強制所有傳入的流量去掉www,如果它存在,只是去/博客/什麼都是頁 - 你試 - 我需要它進入請求的頁面,目前如果你在/博客URL(/ blog/ANY-PAGE-HERE)末尾有任何內容,它默認爲/博客。強制重定向www.domain.com blog到domain.com blog .htaccess?

任何人有任何想法如何我會去解決這個問題?在.htaccess似乎是最簡單的方法,但我似乎無法找到一個可行的解決方案後工作幾個小時。

PS:這是多站點,所以我不能隨便進入設置和更改URL和家庭www.domain /博客

回答

1

這是我在我的網站上使用:

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    # If your site can be accessed both with and without the 'www.' prefix, you 
    # can use one of the following settings to redirect users to your preferred 
    # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option: 
    # 
    # To redirect all users to access the site WITH the 'www.' prefix, 
    # (http://example.com/... will be redirected to http://www.example.com/...) 
    # adapt and uncomment the following: 
    RewriteCond %{HTTP_HOST} ^domain\.net$ [NC] 
    RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301] 
</IfModule> 
+0

沒有任何理由不工作。感謝您的答案,雖然 – mmundiff 2012-07-12 20:06:33

+0

是否在您的Apache構建中啓用了MOD_REWRITE?使用'apache2 -t -D DUMP_MODULES'來找出是否列出rewrite_module。 – 2012-07-12 20:09:42

+0

是。我在整個服務器上使用它。我在一個子文件夾\博客的根和wordpress中有一個主CMS。主CMS不會在www或非www中出現問題。儘管如此,WordPress的多站點安裝。 – mmundiff 2012-07-12 20:21:42

0

添加這上面您的文檔根目錄的htaccess中的所有WordPress的東西:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.domain\.net$ [NC] 
RewriteRule ^blog(.*) http://domain.net/blog$1 [L,R=301] 
相關問題