使用.htaccess的HTTP到https重定向不起作用
我想将 http://myip/admin 重定向到
I want to redirect http://myip/admin to https://myip/admin. I am trying to use .htaccess to do this (want this only for the admin folder).
.htaccess的内容放在相关文件夹中:
Contents of .htaccess placed in the relevant folder:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
(已启用Apache mod_rewrite). http://myip/admin 和 https://myip/admin 可见(但是重定向不起作用).服务器是Ubuntu.
(apache mod_rewrite is enabled). Both http://myip/admin and https://myip/admin are visible (but the redirection does not work). Server is Ubuntu.
我从互联网上尝试了上述规则的几种变体,但没有运气:(
I have tried few variations of the above rules from the internet but no luck :(
任何输入将不胜感激.
致谢,JP
解决了该问题并学到了一些新知识.apache的主配置文件中的AllowOverride选项未正确设置.
Solved it and learnt something new. The AllowOverride option in apache's main config file was not set correctly.
此外,如果有人遇到这样的问题,请注意2分:1)apache重新加载有时可能无法正常工作.尝试重新启动2)清除浏览器缓存和/或刷新页面.
Also, if someone faces such issues 2 points: 1) apache reload may sometime not work as expected. Try restart 2) Clear browser cache and / or refresh page.