Php 通过htaccess将所有非https请求重定向到https请求
您好,这是我的htaccess,我有我的https。我想将所有非https重定向到https,而不影响我的get/post变量和任何其他链接,只需将站点移动到https即可 htaccess文件Php 通过htaccess将所有非https请求重定向到https请求,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,您好,这是我的htaccess,我有我的https。我想将所有非https重定向到https,而不影响我的get/post变量和任何其他链接,只需将站点移动到https即可 htaccess文件 RewriteEngine On RewriteBase / Options All -Indexes RewriteCond %{REQUEST_METHOD} POST [NC] RewriteRule ^ - [L] ErrorDocument 403 /www
RewriteEngine On
RewriteBase /
Options All -Indexes
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
ErrorDocument 403 /www.domain.com/error404.php
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]
# redirect /dept?did=1 to /did/1
RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /did/1 to /dept.php?did=1
RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ enterprise.php?url=$1 [L,QSA]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
我已尝试将代码添加到我的htaccess文件中
RewriteEngine On
RewriteBase /
Options All -Indexes
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
ErrorDocument 403 /www.domain.com/error404.php
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]
# redirect /dept?did=1 to /did/1
RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /did/1 to /dept.php?did=1
RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ enterprise.php?url=$1 [L,QSA]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
但它会将站点重定向到错误页面,但处于https模式
我在htaccess页面的403错误处理程序之后添加了代码
我不太擅长htaccess,请给我提些建议。。
只需在第一次尝试时将站点重定向到https而不是http上,您应该告诉它使用
R标志重定向,并提供一个状态code
,这将有助于您的SEO。把这条规则作为你的第一条规则
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#all other rules below
你应该告诉它使用R标志重定向,并提供一个状态code
,这将有助于你的搜索引擎优化。把这条规则作为你的第一条规则
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#all other rules below