【发布时间】:2018-05-09 08:05:57
【问题描述】:
我无法将我的 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 但如果我从 url 手动删除 www 它不会重定向到 www 。
【问题讨论】:
-
# 不要放 www。这里。如果它已经存在,它将被包括在内,如果没有 - 这是在同一行吗?它看起来像一个错字。
-
是的,它在同一行
-
我没有正确阅读您的问题。请检查:stackoverflow.com/a/17458396/6811933
-
我试过了,但它不起作用......早期代码的问题就像我去“
http://domain.in”=>“https://www.domain.in”时一样......这很好....但是如果我在这种情况下转到“https://domain.in”=>“https://domain.in”,则网址重定向不会强制它添加 www -
如果我要去
http://domain.in/profile/,它既不会重定向https,也不会重定向www
标签: .htaccess redirect apache2