我无法将我的example.in定向到https://www.example.in我使用的是.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if
not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
AcceptPathInfo On
我发现这个代码在stackoverflow,但它不工作在我的项目我的网站是在AWS和使用apache2 php 7. 0的虚拟主机
它不是强制www和我已经尝试了其他代码。htaccess,但如果我手动删除www从url,它不会重定向到www。
2条答案
按热度按时间ltqd579y1#
谢谢大家的支持,
我已经解决了我的问题,这是因为
ssl
是安装在我的网站上,因此在/etc/apache2/sites-available/
我发现
default-ssl.conf
文件,其中包含一些设置,我猜不允许我ovveride与.htaccess
。但现在添加了
htaccess工作正常。
jckbn6z72#