【发布时间】:2015-10-23 05:53:05
【问题描述】:
在我的域中将带有 www 的规范 URL 重写为非 www 时遇到问题。 如果我尝试 www.example.com 并且总是得到#404。 这是有关 apache2 配置的所有信息。
这是我检查的所有内容:
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin info@example.com
ServerName example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
AllowOverride All
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/apache2.conf
.
.
.
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
.
.
.
有什么想法吗? 谢谢!
【问题讨论】:
-
您确定问题是您认为的问题吗?毕竟,您可能也有一些使用该 url 的源代码。所以,我想你应该检查 htaccess 和你的源代码是否存在潜在问题。另外,看看重写规则。
-
BTW Allowoverride 对您的配置重写规则没有影响,因为您不使用 .htaccess 而是在配置中使用重写。因此,为防止不必要的性能损失,请将其关闭。
AllowOverride None。配置更改后您是否也重新启动了 apache? -
我尝试过使用 .htaccess,每次更改后我都重新启动了 apache。
标签: .htaccess mod-rewrite apache2 no-www