2016-11-29 71 views
0

我需要一個網站,讓所有的URL沒有www前面。爲此,我在這裏找到了一些有用的代碼,這些代碼對我有很大的幫助。但是,我無處可以找到如何正確執行所有請求URI。目前它只能在域名主頁上運行。非www重寫規則不處理請求URI

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC] 
RewriteRule ^(.*)$ https://domain.nl%{REQUEST_URI} [L,R=301] 
</IfModule> 


# END WordPress 

現在www.domain.nl被重寫到domain.nl中。然而,像www.domain.nl/anything_else之類的任何其他內容都不會被重寫(也嘗試在%{REQUEST_URI}之前添加/,但不起作用)。

任何幫助表示讚賞!

回答

0

以www規則之前:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC] 
RewriteRule^https://domain.nl%{REQUEST_URI} [NE,L,R=301] 

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule>