[英]https redirection via .htaccess not working
我正在使用apache
和laravel
並希望將我的所有請求重定向到https
。 例如:我想要這個網址
abc.com/my/test
重定向到
目前我在文件中有以下代碼
/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>
問題: adobe htaccess
設置執行重定向,但路徑錯誤。 重定向到
我希望將其重定向到上述鏈接。
[L]標志使mod_rewrite停止處理規則集。 在大多數情況下,這意味着如果規則匹配,將不再處理其他規則。
https://httpd.apache.org/docs/current/rewrite/flags.html
您可以嘗試刪除該行上的[L]
標志:
RewriteRule ^ index.php [L]
您也可以使用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.