我正在关注laravel的快速启动,它说"type /users"
但不适合我。
我在浏览器中写道http://DomainServer/ProjectName/users
并抛出:
在此服务器上找不到请求的URL / ProjectName / users。 Laravel
我尝试了以下内容,
启用apache模块mod_rewrite
并且也不起作用。
答案 0 :(得分:37)
Linux环境中Apache Web Server和Laravel的步骤。
打开httpd.conf
sudo vim /etc/httpd/conf/httpd.conf
# for debian users: /etc/apache2/apache2.conf
确保DocumentRoot指向laravel项目的公共目录
添加该路径的Directory元素和Allowoverride All ...,如下所示
DocumentRoot "/var/www/html/laravel/public/"
<Directory "/var/www/html/laravel/public">
Allowoverride All
</Directory>
从../laravel/public/打开.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>
重启httpd服务
sudo service httpd restart
现在http://DomainServer/users
可以在您的浏览器中使用。
答案 1 :(得分:4)
首先在Laravel项目中找到htaccess文件
接下来在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]
保存htaccess文件
使用以下代码重新启动apache服务器
sudo service apache2 restart
请记住,htaccess文件和index.php文件必须在项目的同一文件夹中可用
答案 2 :(得分:3)
找到httpd.conf并从
更改<Directory>
元素
<Directory "/var/www/html/">
Allowoverride None
</Directory>
到
<Directory "/var/www/html/">
Allowoverride All
</Directory>
然后在重新启动apache后无需更改DocumentRoot
。
答案 3 :(得分:1)
尝试将浏览器指向http://DomainServer/ProjectName/public/users
- “公共”文件夹是Laravel应用的默认“入口点”。
答案 4 :(得分:1)
默认网址有前缀&#34; index.php&#34;在您的页面之前如果您尝试... / public / index.php / your_page它将运行,因此如果您使用appache编写没有此前缀的URL,则需要添加模块重写
答案 5 :(得分:1)
确保在Apache中启用了mod_rewrite。
答案 6 :(得分:0)
对我来说,我启用了mod_rewrite,它对我很有用。 为Apache启用mod_rewrite: cd / etc / apache2 / sites-available / sudo a2enmod重写
答案 7 :(得分:0)
在我的情况下,我想以未经身份验证的用户身份获取此路由。 RouteServiceProvider 有默认值:
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
这意味着您需要将前缀“api/”添加到您的网址中,例如:
http://yourdomain.com/api/route_url_part
然后将路由放到 api.php ,而不是 web.php 至 auth 'middlwared'
(可选用于 Android 模拟器) 如果您尝试在 android 模拟器中执行此操作,则必须关闭服务器并将其启动为:
php artisan serve --host=0.0.0.0
并且在java android url而不是localhost中放入从提示窗口的ipconfig命令检索的ip。假设我的是 192.168.0.106 (IPv4 地址之一)。然后它会起作用。