[英]htaccess remove www redirect to ssl but wrong url
我用 php 创建了一个 mvc 框架。 我唯一工作的主文件是 index.php。
通常我从 http 重定向到 https。 我也删除了 www 域,但是当我输入 www 时,如果我的 URL 是例如
domain.com/admin/products/edit/1,
htaccess 这样做。
domain.com/index.php/products/edit/1
我该如何解决这个谢谢
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
你应该有这样的规则,总是把 https 重定向规则放在第一位。 请在测试您的 URL 之前清除您的浏览器缓存(其余规则来自 OP 的尝试规则 + 我在这里也更改了匹配主机名的正则表达式)。
RewriteEngine ON
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} ^(?:www\.)(example\.com) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.