2014-07-08 45 views
1

我的網站正在運行virtualmin控制面板的虛擬服務器當前正在重定向302臨時URL,而我在.htaccess文件中添加了重定向規則。如何使用301永久性重定向將www url重定向到非www網址?

這裏是我的.htaccess文件中的配置:

Options -Indexes 
RewriteEngine On 
RewriteBase/

RewriteRule ^index.html$ index.php 
RewriteRule ^(([a-zA-Z0-9-_]+)?)\.html$ page.php?pagId=$1 
RewriteCond %{http_host} !^example.com$ [nc] 
RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc,L] 

請讓我知道什麼樣的變化,我需要在我的Web服務器,使所以正確重定向301永久重定向?

我想以這種URL格式「https://example.com/」重定向我的域的所有請求。

回答

0

我已經解決了這個問題。一個在每一臺虛擬主機

我保持相同的.htaccess文件 >

  Options -Indexes 
     RewriteEngine On 
     RewriteBase/
     RewriteCond %{HTTP_HOST} !^example\.com$ [NC] 
     RewriteRule^https://example.com%{REQUEST_URI} [R=301,NE,L] 
     RewriteRule ^index\.html$ index.php [L,NC] 
     RewriteRule ^([\w-]+)\.html$ page.php?pagId=$1 [L,NC,QSA] 

而且在/etc/httpd/conf/httpd.conf中文件 >

 <VirtualHost*:80> 
     . 
     . 
     RewriteEngine on 
     RewriteCond %{HTTP_HOST} !^example\.com$ [NC] 
     RewriteRule^https://example.com%{REQUEST_URI} [R=301,NE,L] 
     </VirtualHost> 


     <VirtualHost*:443> 
     . 
     . 
     RewriteEngine on 
     RewriteCond %{HTTP_HOST} !^example\.com$ [NC] 
     RewriteRule^https://example.com%{REQUEST_URI} [R=301,NE,L] 
     </VirtualHost> 

現在,它的工作精細。

希望這可以幫助某人。

0

您可以使用:通過寫兩個重寫規則

Options -Indexes 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^example\.com$ [NC] 
RewriteRule^https://example.com%{REQUEST_URI} [R=301,NE,L] 

RewriteRule ^index\.html$ index.php [L,NC] 

RewriteRule ^([\w-]+)\.html$ page.php?pagId=$1 [L,NC,QSA] 
+0

非常感謝anubhava的幫助,但仍然無法工作302重定向。 – user128296

+0

您在瀏覽器中輸入了哪個網址,哪些網址無效?這個.htaccess位於哪裏? – anubhava

+0

由於Anubhava問題已解決。 – user128296

相關問題