其他路线而非默认路线不适用于 XAMPP
Other routes rather than default one not working with XAMPP
我有我的 Laravel 项目,而不是 运行ning 在我的本地主机上 XAMPP 如果我使用地址“localhost/app/public”,我会得到主要的(即欢迎) page(welcome.blade.php) 工作,但是当我写我的其他路线时,如“localhost/app/public/anyother”,它显示错误消息,404 |未找到。
虽然默认路由和所有其他路由都适用于“php artisan serve”。
我想知道两件事希望你不要介意。
1.如何解决 XAMPP 在 Laravel 自己的应用程序服务器上所有路由都可以正常访问的问题?
2。为什么其他路由在本地 XAMPP 中不起作用,而它们在“php artisan serve”中运行良好?
我在 XAMPP 上为 运行 Laravel 应用程序找到的是:-
与xampp合作:
转到 C:\Windows\System32\drivers\etc\hosts 并添加一个新行,如:127.0.0.1 yoursite.local
转到 xampp\apache\conf\extra\httpd-vhosts.conf 下安装 XAMPP 的位置然后在文件底部添加一个虚拟主机,如:
<VirtualHost *:80>
DocumentRoot "PATH_to_laravel_folder/public"
ServerName yoursite.local
</VirtualHost>
如果我接受第 1 点的这个解决方案,是否还有其他不创建虚拟主机的解决方案?如果我想使用 XAMPP 提供的任何其他解决方案 URL 例如“localhost/app/public”?
你的虚拟主机不好。您忘记了 Directory
规范标签并且不允许索引。
尝试像这样编辑位于 C:\xampp\apache\conf\extra\httpd-vhosts.conf
中的 httpd-vhosts.conf
:
# VirtualHost for LARAVEL.DEV
<VirtualHost laravel.dev:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\laravel">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
您可以在 Apache documentation
中找到更多信息
<Directory>
and </Directory>
are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories.
换句话说,使用 Options +Indexes
或 Options Indexes
指令启用 Apache Web 服务器自动索引生成。
If a URL which maps to a directory is requested, and there is no DirectoryIndex
in that directory, then mod_autoindex
will return a formatted listing of the directory.
解决方案一:
尝试将 Laravel 项目文件夹中的 server.php
重命名为 index.php
并将 public 目录中的 .htaccess
文件复制到项目根文件夹.
方案二:
将.htaccess
和index.php
从public目录复制到项目根文件夹
更改 index.php
文件,地址如下:
//change line 22 to
require __DIR__.'/bootstrap/autoload.php';
//change line 36 to
$app = require_once __DIR__.'/bootstrap/app.php';
希望上述解决方案之一适用于您的情况。
我有我的 Laravel 项目,而不是 运行ning 在我的本地主机上 XAMPP 如果我使用地址“localhost/app/public”,我会得到主要的(即欢迎) page(welcome.blade.php) 工作,但是当我写我的其他路线时,如“localhost/app/public/anyother”,它显示错误消息,404 |未找到。 虽然默认路由和所有其他路由都适用于“php artisan serve”。
我想知道两件事希望你不要介意。
1.如何解决 XAMPP 在 Laravel 自己的应用程序服务器上所有路由都可以正常访问的问题?
2。为什么其他路由在本地 XAMPP 中不起作用,而它们在“php artisan serve”中运行良好?
我在 XAMPP 上为 运行 Laravel 应用程序找到的是:-
与xampp合作:
转到 C:\Windows\System32\drivers\etc\hosts 并添加一个新行,如:127.0.0.1 yoursite.local 转到 xampp\apache\conf\extra\httpd-vhosts.conf 下安装 XAMPP 的位置然后在文件底部添加一个虚拟主机,如:
<VirtualHost *:80>
DocumentRoot "PATH_to_laravel_folder/public"
ServerName yoursite.local
</VirtualHost>
如果我接受第 1 点的这个解决方案,是否还有其他不创建虚拟主机的解决方案?如果我想使用 XAMPP 提供的任何其他解决方案 URL 例如“localhost/app/public”?
你的虚拟主机不好。您忘记了 Directory
规范标签并且不允许索引。
尝试像这样编辑位于 C:\xampp\apache\conf\extra\httpd-vhosts.conf
中的 httpd-vhosts.conf
:
# VirtualHost for LARAVEL.DEV
<VirtualHost laravel.dev:80>
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin laravel.dev
<Directory "C:\xampp\htdocs\laravel">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
您可以在 Apache documentation
中找到更多信息
<Directory>
and</Directory>
are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories.
换句话说,使用 Options +Indexes
或 Options Indexes
指令启用 Apache Web 服务器自动索引生成。
If a URL which maps to a directory is requested, and there is no
DirectoryIndex
in that directory, thenmod_autoindex
will return a formatted listing of the directory.
解决方案一:
尝试将 Laravel 项目文件夹中的 server.php
重命名为 index.php
并将 public 目录中的 .htaccess
文件复制到项目根文件夹.
方案二:
将.htaccess
和index.php
从public目录复制到项目根文件夹
更改 index.php
文件,地址如下:
//change line 22 to
require __DIR__.'/bootstrap/autoload.php';
//change line 36 to
$app = require_once __DIR__.'/bootstrap/app.php';
希望上述解决方案之一适用于您的情况。