我希望我的拉威尔应用程序可以访问或不在url上的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>关于服务器的事,我是菜鸟。
发布于 2015-05-16 23:06:59
您的apache配置正确。但是,您需要启用重写模块:
sudo a2enmod rewrite
sudo service apache2 restart如果您使用的是已注册的域名,这就足够了。如果您只是使用“本地”域进行开发,则必须将此转储域添加到位于/etc/hosts的主机文件中。例如,当使用本地环境时,我通常使用域.local,我将添加下面这一行来使域example.local工作:
127.0.0.1 example.local发布于 2015-05-18 00:39:35
您需要包括要在主机文件中使用的所有可能的域名/子域名组合。
127.0.0.1 www.example.com
127.0.0.1 example.com关于http://www.example.com/contact,http://example.com/contact能工作吗?
https://stackoverflow.com/questions/30276206
复制相似问题