我是laravel的新手,我在linux服务器上使用composer安装了laravel,问题是我无法访问domainname.com,但domainname.com/public/然后只有我才能访问该页面。请建议我如何使用domainname.com/而不是domainname.com/public/访问网站
我在共享主机中运行,所以有多个域名和文件夹也可用。
首先,确保您的重写模块已启用。在您的情况下,共享托管提供商通常会为您启用它。
其次,在主文件夹中创建一个包含此内容的.htaccess
文件(该文件夹包含artisan
文件)。
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
您需要添加一个<虚拟主机>在Apache配置中:
<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
然后您可以访问您的Laravel网站:http://your.domain.com/