http到https重定向htaccess不起作用


http to https redirect htaccess not working

我找到了很多类似的答案,但到目前为止,我无法找到我想要的正确答案。这看起来很容易,或者可能有人已经回答了,但对我来说,它已经不起作用了。。

所以最后我想要https://example.com/product/624567

在我的htaccess文件中,我已经有了一个类似的规则

RewriteEngine On
RewriteRule ^([a-z0-9-]{1,40})/([0-9]{1,12})$ fixMe.php?request=$2 [L]

现在,如果有人按照上面提到的模式调用URL,无论是否使用https,它都应该重定向到所需的URL(https://example.com/product/624567)。为了实现这个重定向,我设置了另一个类似的规则

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} product
RewriteRule ^product/([0-9]{1,12})$ https://%{HTTP_HOST}/product/$1 [L,R=301,NE]

但我总是得到404错误!!有人能帮我做错事吗。感谢

尝试使用:

RewriteCond %{HTTPS} off
RewriteRule ^product/[0-9]{1,12}$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,NE,L,R=301] 

但只需将线放在RewriteEngine On之后和RewriteRule ^([a-z0-....之前;