iT邦幫忙

1

.htaccess設定問題 - 強制https瀏覽同時簡化網址

大家好~

如題,想請教有可能在強制https瀏覽的同時簡化網址嗎?

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteRule ^([^?]*) product.php?_route_=$1 [L,QSA]

目前上述的測試結果
會從http轉到https但chrome會顯示ERR_TOO_MANY_REDIRECTS...

fillano iT邦超人 1 級 ‧ 2016-09-01 07:10:14 檢舉
第二個RewriteRule要加上RewriteCond,排除網址有product.php的狀況。
tibandyli iT邦新手 2 級 ‧ 2016-09-01 11:54:20 檢舉
看起來是這個問題~

不過,早上也試了另一個解法 把apache virtulhost 裡的http與https拆開…
http只做轉址https做縮短網址 不過,還fillano大的方法比較方便
tibandyli iT邦新手 2 級 ‧ 2016-09-01 12:51:47 檢舉
怪了...加入
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/?(product.php)
RewriteCond %{REQUEST_URI} !^/?(product\.php)
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteRule ^([^?]*) product.php?_route_=$1 [L,QSA]
一樣出錯....
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
fillano
iT邦超人 1 級 ‧ 2016-09-01 07:19:44
最佳解答

第二個RewriteRule要加上RewriteCond,排除網址有product.php的狀況。

請參考:http://httpd.apache.org/docs/current/rewrite/flags.html#flag_l 的說明。

tibandyli iT邦新手 2 級 ‧ 2016-09-01 11:52:23 檢舉

謝謝您的回答^^
看起來是這個問題了~

tibandyli iT邦新手 2 級 ‧ 2016-09-05 11:59:38 檢舉

加入

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/?(product.php)
RewriteCond %{REQUEST_URI} !^/?(product\.php)
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteRule ^([^?]*) product.php?_route_=$1 [L,QSA]

一樣出錯....

fillano iT邦超人 1 級 ‧ 2016-09-05 13:37:54 檢舉

我沒測試過,不過你的規則有點怪。先把

RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

移到這個RewriteCond後面:

RewriteCond %{SERVER_PORT} !^443$

看看。另外,要測試是否是透過http進來的request,可以測試這樣的RewriteCond,比較明確一點。

RewriteCond %{HTTPS} ^off$

然後再把它轉到https。

我要發表回答

立即登入回答