我無法將url查詢參數重寫(花式url)與.htaccess ssl重定向結合起來。.htaccess用ssl重定向url重寫
我的.htaccess文件是目前:
Options +FollowSymLinks
Options -Indexes
ServerSignature Off
RewriteEngine on
RewriteBase/
# in https: process secure.html in https
RewriteCond %{server_port} =443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
# in https: force all other pages to http
RewriteCond %{server_port} =443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+).html$ http://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: force secure.html to https
RewriteCond %{server_port} !=443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+).html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: process other pages as http
RewriteCond %{server_port} !=443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
的花式URL重寫工作正常,但重定向/從https是不工作的。
如果我
RewriteRule ^(.+).html$ https://%{HTTP_HOST}/index.php?page=$1 [QSA,L]
替換包含
RewriteRule ^(.+).html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
2線則HTTPS重定向工作正常,但花哨,URL重寫無法正常工作。
這兩者可以結合嗎?
編輯:
所期望的結果是:
1. http://domain.com/secure.html is rewritten to https://domain.com/index.php?page=secure
2. http://domain.com/foo.html is rewritten to http://domain.com/index.php?page=foo
3. https://domain.com/secure.html is rewritten to https://domain.com/index.php?page=secure
4. https://domain.com/foo.html is rewritten to http://domain.com/index.php?page=foo
(我不得不把它們放在一個代碼塊爲超過1個鏈接是不允許新用戶)
所以secure.html始終是https,而foo.html(所有其他頁面)始終是http。
解決方案:
由於濃湯,解決的辦法是:
Options +FollowSymLinks
Options -Indexes
ServerSignature Off
RewriteEngine on
RewriteBase/
# in https: force all other pages to http
RewriteCond %{server_port} =443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in http: force secure.html to https
RewriteCond %{server_port} !=443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+)\.html$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,N]
# in https: process secure.html in https
RewriteCond %{server_port} =443
RewriteCond $1 ^secure$ [NC]
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA,L]
# in http: process other pages as http
RewriteCond %{server_port} !=443
RewriteCond $1 !^secure$ [NC]
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA,L]
你能舉一個你預計會發生什麼和發生什麼的例子嗎? – Gumbo 2010-03-14 18:39:19