Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php HttAccess将http重定向到https的问题_Php_Apache_.htaccess_Redirect_Https - Fatal编程技术网

Php HttAccess将http重定向到https的问题

Php HttAccess将http重定向到https的问题,php,apache,.htaccess,redirect,https,Php,Apache,.htaccess,Redirect,Https,我在服务器中的htaccess文件有问题。当试图将http重定向到https时,它疯了 如果我这样做: ErrorDocument 400 /errores/error400.php ErrorDocument 404 /errores/error404.php ErrorDocument 403 /errores/error403.php Options +FollowSymLinks RewriteEngine on RewriteRule ^([A-Za-z0-9_-]+)$ /index

我在服务器中的htaccess文件有问题。当试图将http重定向到https时,它疯了

如果我这样做:

ErrorDocument 400 /errores/error400.php
ErrorDocument 404 /errores/error404.php
ErrorDocument 403 /errores/error403.php
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9_-]+)$ /index.php?lang=$1
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?lang=$1&go=$2
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?lang=$1&go=$2&action=$3
它工作正常,只是没有将http重定向到https

但当我说:

ErrorDocument 400 /errores/error400.php
ErrorDocument 404 /errores/error404.php
ErrorDocument 403 /errores/error403.php
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^([A-Za-z0-9_-]+)$ /index.php?lang=$1
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?lang=$1&go=$2
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?lang=$1&go=$2&action=$3
服务器重定向到https,而不是像https://server.com/en/home 是的https://server.com/folder1/folder2/web/portal/en/home

我不知道该怎么做


提前感谢

我建议您将重写规则与标志相匹配,尤其是对于HTTPS重定向

以下是我的生产服务器的工作原理:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

当您放置[L]时,它会告诉apache停止处理以下规则,这些规则也匹配。*。您可以在此处找到有关该标志的更多信息:

谢谢您的回答,但它不起作用,它会在主机之后删除整个url。你的原始陈述和我的建议相结合也许会起作用,而不是你的情况。我会尝试使用你的RewriteCond%{HTTPS}!打开并重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}但在重写规则之后添加[R=301,L]。什么是/folder1/folder2/web/portal?你在使用CMS框架吗?抱歉,耽搁了,我在旅行,不,我没有,它是我服务器中的一个子文件夹。我有主要的public_html/和你在问题中看到的路径,但是你的规则都没有重定向到/folder1/folder2/web/portal,所以必须有一些配置文件重定向到/folder1/folder2/web/portal