首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Apache2.4上使用www访问域

问如何在Apache2.4上使用www访问域
EN

Stack Overflow用户
提问于 2015-05-16 21:23:01
回答 2查看 81关注 0票数 1

我希望我的拉威尔应用程序可以访问或不在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

代码语言:javascript
复制
<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文件

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>

关于服务器的事,我是菜鸟。

EN

回答 2

Stack Overflow用户

发布于 2015-05-16 23:06:59

您的apache配置正确。但是,您需要启用重写模块:

代码语言:javascript
复制
sudo a2enmod rewrite
sudo service apache2 restart

如果您使用的是已注册的域名,这就足够了。如果您只是使用“本地”域进行开发,则必须将此转储域添加到位于/etc/hosts的主机文件中。例如,当使用本地环境时,我通常使用域.local,我将添加下面这一行来使域example.local工作:

代码语言:javascript
复制
127.0.0.1 example.local
票数 0
EN

Stack Overflow用户

发布于 2015-05-18 00:39:35

您需要包括要在主机文件中使用的所有可能的域名/子域名组合。

代码语言:javascript
复制
127.0.0.1 www.example.com
127.0.0.1 example.com

关于http://www.example.com/contact,http://example.com/contact能工作吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30276206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档