我無法將http://example.com/test
重定向到https://example.com/test
。它總是會重定向到主頁。我在谷歌搜索了幾個小時,但沒有解決方案。下面是我的.htaccess
:在htaccess中強制http https,總是重定向到主頁
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule^- [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule^- [E=protossl:s]
RewriteRule^- [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule "(^|/)\." - [F]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule^http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule^index.php [L]
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
Header set Content-Encoding gzip
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
<IfModule mod_headers.c>
Header always set X-Content-Type-Options nosniff
</IfModule>
我也不知怎麼管理,以達到我想要的,通過註釋:
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule^index.php [L]
但它會導致另一個問題,我的網站。當我訪問後端系統時,我收到了404錯誤,並導致我的網站中斷。任何人都可以指出我正確的方向嗎?
它沒有將網站重定向到https。現在,所有css,js和img都無法加載狀態404. –
失敗的CSS,JS和圖像表示客戶端HTML中的相對URL。但是,沒有明顯的理由說明,如果在您將_front控制器_註釋掉之前重定向了,它將不會重定向。 SSL如何管理?我已經更新了我的答案 - 請注意,您的非www重定向的規範www也應該在文件的開頭。將您更新的'.htaccess'文件發佈到您的問題。 – MrWhite
我設法通過使用另一個drupal模塊(seckit)來解決這個問題。謝謝你的幫助。 –