将HTTP请求重定向到HTTPS请求

时间:2018-07-27 作者:chaos thunder

我正在运行一个不在Wordpress上的网站,它是由另一个开发人员使用自定义框架构建的,太可怕了。这就是我现在发疯的原因。

目前,我需要将用户对我们网站的请求重写如下:

HTTP to HTTPS redirection goal

我尝试了很多没有运气的事情。%{SERVER\\u PORT}80是我尝试过的事情之一。

下面是我的。htaccess的内容:

Options +FollowSymlinks

DirectoryIndex home.html index.php

Options -Indexes

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^www.dongduong.edu\\.vn [OR,NC]
RewriteRule ^(.*) https://dongduong.edu.vn/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9_-]+).html&vcb=([a-zA-Z0-9_-]*)&key_oder=([a-zA-Z0-9_-]*)$ index.php?com=$1&vcb=$2&key_order=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&noidi=([a-zA-Z0-9_-]*)&noiden=([a-zA-Z0-9_-]*)&date=([a-zA-Z0-9_-]*)&gia=([a-zA-Z0-9_-]*)$ index.php?com=$1&noidi=$2&noiden=$3&date=$4&gia=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&diadiem=([a-zA-Z0-9_-]*)&sao=([a-zA-Z0-9_-]*)&gia=([a-zA-Z0-9_-]*)$ index.php?com=$1&diadiem=$2&sao=$3&gia=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p=([0-9]+)$ index.php?com=$1&p=$2    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&curPage=([0-9]+)$ index.php?com=$1&curPage=$2  [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p1=([0-9]+)$ index.php?com=$1&p1=$2    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&p=([0-9]+)&p1=([0-9]+)$ index.php?com=$1&p=$2&p1=$3    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html$ index.php?com=$1  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)&p=([0-9]+)$ index.php?com=$1&idc=$2&p=$3    [L]
RewriteRule ^([a-zA-Z0-9_-]+).html&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&sapxep=$2  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&idc=$2&sapxep=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&sapxep=([a-zA-Z0-9_-]+)$ index.php?com=$1&idl=$4&idc=$2&sapxep=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&id=$3  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+)_([a-zA-Z0-9_-]+).html$ index.php?com=$1&id=$3&idh=$4  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ index.php?com=$1&idhai=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html&p=([0-9]+)$ index.php?com=$1&id=$3&p=$4  [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?com=$1&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/([0-9]+)$ index.php?com=$1&idi=$2&idi=$3&idi=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/([0-9]+).html$ index.php?com=$1&idl=$2&idl=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&id=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idl=$4&p=$5&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idl=$4&idc=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idi=$5&p=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idi=$5 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html&p=([0-9]+)$ index.php?com=$1&idh=$6&p=$7 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?com=$1&idh=$6 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)_([0-9]+).html$ index.php?com=$1&idc=$2&id=$7 [L]
请帮我做到这一点。

谢谢你的帮助!

1 个回复
SO网友:Rick Hellewell

虽然您的问题的注释中的答案会起作用(这里是格式化的),但根据您的托管环境,可能需要一些变化,因此请联系您的托管支持以了解详细信息。

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

结束