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-page到https://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]
但是,這似乎並沒有工作。