gpt4 book ai didi

apache - 如何在 apache 2.4 上使用 www 使域可访问

转载 作者:行者123 更新时间:2023-12-04 18:51:56 25 4
gpt4 key购买 nike

我希望我的 laravel 应用程序可以使用或不使用 www在网址上。喜欢 [ http://laracasts.com][1] .当我点击 http://example.com有用。但是当我点击 http://www.example.com , 或 http://www.example.com/contact我收到 404 错误。我该如何解决这个问题?我正在使用 apache 2.4.7在 Ubuntu 上,这是我的 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>

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

最佳答案

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

sudo a2enmod rewrite
sudo service apache2 restart

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

关于apache - 如何在 apache 2.4 上使用 www 使域可访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30276206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com