【发布时间】:2019-03-21 10:31:19
【问题描述】:
我已经在我的域上安装了 https。所有这些案例都可以在我的网站上找到:
http://example.com // will be redirected to https://example.com
https://example.com
http://www.example.com // will be redirected to https://www.example.com
https://www.example.com
看到了吗?一切都将使用 https 协议。一切都好。
现在我需要将所有www 重定向到non-www。所以http://www.example.com和https://www.example.com应该重定向到https://example.com(换句话说,所有情况都应该重定向到这个)。
这是我当前在/etc/apache2/sites-avalible/000-default.conf中的代码:
<VirtualHost *:80>
.
.
.
RewriteEngine on
RewriteCond %{SERVER_NAME} =lamtakam.com [OR]
RewriteCond %{SERVER_NAME} =www.lamtakam.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] -- this
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] -- and this are for www redirection
-- but doesn't work
</VirtualHost>
有什么想法吗?
lamtakam 也是我所说的确切域名,如果您需要检查的话。
编辑:
目前我在项目根目录的.htaccess 文件中有这个:
RewriteEngine on
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# this doesn't work on some version of xampp
# RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]
ErrorDocument 404 /error404.html
【问题讨论】:
标签: apache ubuntu-16.04 no-www