301将所有资产从http重定向到https

时间:2014-08-13 13:15:26

标签: apache .htaccess redirect config http-status-code-301

我已经搜索过并尝试过,但在将我的http网站移至完整https时,我似乎无法找到关于如何301重定向所有资产的答案。

我正在寻找一种方法来使用.htaccess或httpd.conf来将所有资产(图像,pdf,视频,js,css,.txt等)从http重定向到https。

http和https的完整结构保持不变。

我很感激有关此主题的任何指导。

由于 威廉

1 个答案:

答案 0 :(得分:1)

# Checking if HTTPS is enabled for current page   
RewriteCond %{HTTPS} !=on 
# Redirecting any non-HTTPS document by this URL to HTTPS URL
RewriteRule (.*)\.(?:jpe?g|gif|bmp|png|tiff|css|js|pdf))$  https://%{SERVER_NAME}/$1.$2 [R=301,L]

从这里采取:https://wiki.apache.org/httpd/RewriteHTTPToHTTPS