2016-03-29 89 views
1

我在我的.htaccess文件中有這個,我想添加一個規則來將我的網站從非www重定向到www。htaccess將參數傳遞給索引並重定向到www

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 
+0

參考:http://stackoverflow.com/questions/12050590/redirect-non-www-to-www-in-htaccess –

回答

0

你可以試試這個

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)index.php$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+0

三江源工程就像一個魅力。我不擅長htaccess,但我知道你是。 – MashiruAlexis

-1

我用下面的代碼我非www URL重定向到一個WWW之一。我將它添加到我的.htaccess文件中,它工作得很好。我希望這段代碼能夠幫助你。只需用您自己的域名替換域名。祝你好運。

 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomainname.com [NC] 
RewriteRule ^(.*)$ http://www.yourdomainname.com/$1 [L,R=301] 
RewriteCond %{THE_REQUEST} ^(.*)index.php 
RewriteRule ^(.*)index.php$ http://www.yourdomainname.com/$1 [R=301,L] 
相關問題