2011-04-19 36 views
-1

我想重寫與www.example.org,https://www.example.orghttp://example.org任何請求https://example.org的Apache2重寫URL在.htaccess

是否有一個簡單的方法來做到這一點?

我目前在我的.htaccess中執行以下操作,但是https://www.example.org - >https://example.org的情況不起作用。

  1. 任何想法,我可能會出錯?
  2. 這也會影響任何搜索引擎排名因爲這個重定向。
  3. 這是網址重定向的最佳做法。

我目前的.htaccess看起來像這樣。

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{HTTP_HOST} example\.org 
RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://example.com%{REQUEST_URI} 
</IfModule> 

感謝

回答

0

在.htaccess文件試試這個:

Options +FollowSymLinks 
RewriteEngine on 

# redirect for http 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$ [NC] 
RewriteCond %{SERVER_PORT} =80 
RewriteRule ^/?(.*)$ https://example.org/$1 [R=301,QSA,L,NE] 

# redirect for https 
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC] 
RewriteCond %{SERVER_PORT} =443 
RewriteRule ^/?(.*)$ https://example.org/$1 [R=301,QSA,L,NE] 

R=301將HTTPS狀態重定向301
L將最後一條規則
NE是無法逃避查詢字符串
QSA會追加你的exis婷查詢參數

$1是你的REQUEST_URI