【发布时间】:2015-05-16 13:23:00
【问题描述】:
我希望我的 laravel 应用程序可以在网址上使用或不使用 www 访问。像 [http://laracasts.com][1].当我点击http://example.com 时,它起作用了。但是当我点击http://www.example.com 或http://www.example.com/contact 时,我收到了 404 错误。我该如何解决这个问题?我在 Ubuntu 上使用 apache 2.4.7,这是我的 example.com.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin foo@bar.com
DocumentRoot /var/www/myproject/public
<Directory /var/www/myproject/public/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
这是我的/etc/hosts 文件
127.0.1.1 example
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
xxxx::0 ip6-localnet
xxxx::0 ip6-mcastprefix
xxxx::1 ip6-allnodes
xxxx::2 ip6-allrouters
xxxx::3 ip6-allhosts
和.htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
关于服务器的东西,我是菜鸟。
【问题讨论】: