apache - .htaccess 使用 laravel 重定向到 ssl

标签 apache .htaccess redirect ssl

我正在尝试使用 .htaccess 重定向到 laravel 中登录 url 上的 ssl。

登录网址类似于:four.number.for.ip/auth/login

如果我用

RewriteCond %{SERVER_NAME} login
RewriteRule .* https://%{SERVER_NAME} [R=301,L]

它不起作用。我试过

%{HTTPS} !=on 

并且有效。 并且 %{SERVER_NAME} 返回 ip/auth/login(我确定,因为 https!=on 有效)

我不明白为什么这行不通。

最佳答案

这应该适合您。让我知道结果如何。

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

编辑给出完整的规则。它应该看起来像这样。

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/auth/login [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

关于apache - .htaccess 使用 laravel 重定向到 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30109925/

相关文章:

php - 内部重写的查询字符串出现在重定向中

php - Apache 重写排除 Assets 目录

.htaccess - 如何解决 SEO 中没有 www 到 www htaccess 规范问题

redirect - 我如何在 nginx 负载均衡器上将 https 重定向到 http

.htaccess - 如何通过 .htaccess 重定向包含智能引号的 URL?

linux - 在哪里管理 apache 后备目录

php - 用 mod_rewrite 或像 PHP 这样的语言处理友好/干净/漂亮的 URL 更好吗?

.htaccess - 谷歌没有按预期索引我的网址

.htaccess RewriteRule 在浏览器中无需更改 URL

bash - 从 airodump-ng 读取实时输出