简体   繁体   English

通过.htaccess的https重定向不起作用

[英]https redirection via .htaccess not working

i am using apache and laravel and want to redirect all my requests to https . 我正在使用apachelaravel并希望将我的所有请求重定向到https For Example: I want this url 例如:我想要这个网址

abc.com/my/test abc.com/my/test

to be redirected to 重定向到

https://abc.123/my/test https://abc.123/my/test

Currently i have below code in the file 目前我在文件中有以下代码

/var/www/html/laravelProjet/public/.htaccess /var/www/html/laravelProjet/public/.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# For redirecting HTTP to HTTPS
# comment & un-comment below lines according to certificates
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

</IfModule>

Issue: The adobe htaccess settings does the redirect but to wrong path. 问题: adobe htaccess设置执行重定向,但路径错误。 It redirects to 重定向到

" https://abc.123/index.php " https://abc.123/index.php

and i want it to be redirected to the link mentioned above. 我希望将其重定向到上述链接。

The [L] flag causes mod_rewrite to stop processing the rule set. [L]标志使mod_rewrite停止处理规则集。 In most contexts, this means that if the rule matches, no further rules will be processed. 在大多数情况下,这意味着如果规则匹配,将不再处理其他规则。

https://httpd.apache.org/docs/current/rewrite/flags.html https://httpd.apache.org/docs/current/rewrite/flags.html

You could try removing the [L] flag on the line: 您可以尝试删除该行上的[L]标志:

RewriteRule ^ index.php [L]

You can also redirect to HTTPS with PHP: 您也可以使用PHP重定向到HTTPS:

if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") {
    $url = "https://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM