2014-09-29 129 views
1

我在這裏使用了各種答案來創建下面的.htaccess腳本。我需要的腳本做的是.htaccess SSL和非SSL與www到非www重定向

1)重定向所有WWW非WWW(例如www.example.com改爲example.com)

2)輸在一個頁面末尾的PHP(用於例如www.example.com/store.php到example.com/store)

3)重定向所有命中的某個特定頁面,以安全的HTTPS版本(例如http://www.example.com/secure-pagehttps://example.com/secure-page

我已經成功除了能夠將www重定向到非www以外的https頁面之外。下面是我的代碼

RewriteEngine On 
RewriteBase/
Options +FollowSymlinks 

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

RewriteCond %{HTTPS} off 
RewriteRule ^secure-page\.php$ https://example.com/secure-page [L,R=301] 

RewriteCond %{HTTPS} off 
RewriteRule ^secure-page/ secure-page [R=301,L] 

RewriteCond %{HTTPS} on 
RewriteRule ^secure-page/ secure-page [R=301,L] 

我已經嘗試添加行

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

但是,這似乎並沒有工作。

回答

0

0)RewriteEngine敘述和選項:

RewriteEngine On 
RewriteBase/
Options +FollowSymlinks +MultiViews 

1)重定向到WWW非www:

RewriteCond %{HTTP_HOST} ^www\. 
RewriteRule (.*) http://example.com%{REQUEST_URI} [L,R=301] 

2)使用MultiViews選項。

3)重定向到https:

RewriteCond %{HTTPS} off 
RewriteRule ^secure-page https://example.com/secure-page [L,R=301]