php 在此服务器上找不到请求的 URL /ProjectName/users。Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21458080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:09:59  来源:igfitidea点击:

The requested URL /ProjectName/users was not found on this server. Laravel

phplaravel

提问by Luillyfe

I am following the quickstart of laravel and it said "type /users"but not working for me. I have wrote in the browser, http://DomainServer/ProjectName/usersand it throws:

我正在关注laravel的快速入门,它说"type /users"但对我不起作用。我在浏览器中写过,http://DomainServer/ProjectName/users它抛出:

The requested URL /ProjectName/users was not found on this server. Laravel

在此服务器上找不到请求的 URL /ProjectName/users。Laravel

I tried the following,

我尝试了以下,

To enable the apache module mod_rewriteand also does not work.

要启用apache模块mod_rewrite也不起作用。

回答by Andrew Smith

Steps for Apache Web Server and Laravel in Linux Environment.

Linux 环境中 Apache Web Server 和 Laravel 的步骤。

  1. Open httpd.conf

    sudo vim /etc/httpd/conf/httpd.conf
    # for debian users: /etc/apache2/apache2.conf
    
  2. Make sure the DocumentRoot is pointing to the laravel project's public directory

  3. Add the Directory element for that path and Allowoverride All... as follows

    DocumentRoot "/var/www/html/laravel/public/"
    
    <Directory "/var/www/html/laravel/public">
    Allowoverride All
    </Directory>
    
  4. Open .htaccess from ../laravel/public/ and make sure it has the following

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ / [L,R=301]
    
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    </IfModule>
    
  5. Restart httpd services

    sudo service httpd restart
    
  6. Now http://DomainServer/userswill work in your browser.

  1. 打开 httpd.conf

    sudo vim /etc/httpd/conf/httpd.conf
    # for debian users: /etc/apache2/apache2.conf
    
  2. 确保 DocumentRoot 指向 laravel 项目的公共目录

  3. 为该路径添加 Directory 元素并 Allowoverride All... 如下

    DocumentRoot "/var/www/html/laravel/public/"
    
    <Directory "/var/www/html/laravel/public">
    Allowoverride All
    </Directory>
    
  4. 从 ../laravel/public/ 打开 .htaccess 并确保它具有以下内容

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ / [L,R=301]
    
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    </IfModule>
    
  5. 重启httpd服务

    sudo service httpd restart
    
  6. 现在http://DomainServer/users将在您的浏览器中工作。

回答by Mathesh Raj

First find the htaccess file in your Laravel project

首先在你的 Laravel 项目中找到 htaccess 文件

next add the following coding in htaccess file

接下来在 htaccess 文件中添加以下代码

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

save the htaccess file

保存 htaccess 文件

and restart the apache server using following code

并使用以下代码重新启动apache服务器

sudo service apache2 restart

remember htaccess file and index.php file must be available in same folder in your project

记住 htaccess 文件和 index.php 文件必须在你的项目的同一个文件夹中

回答by wasmetqall

Find httpd.conf and change the <Directory>element from

找到 httpd.conf 并将<Directory>元素从

<Directory "/var/www/html/">
Allowoverride None
</Directory>

to

<Directory "/var/www/html/">
Allowoverride All
</Directory>

Then it works after restart the apache without change the DocumentRoot.

然后它在重新启动 apache 后工作而不更改DocumentRoot.

回答by Gadoma

Try pointing your browser to http://DomainServer/ProjectName/public/users- the 'public' folder is the default 'entry point' for your Laravel app.

尝试将浏览器指向 http://DomainServer/ProjectName/public/users- “public”文件夹是 Laravel 应用程序的默认“入口点”。

回答by Amine Achalhi

the default url have a prefix "index.php" before your page if you try .../public/index.php/your_page it will run, so you need to add the module rewrite if you are using appache to write your url without this prefix

如果您尝试 .../public/index.php/your_page,默认 url 在您的页面前有一个前缀“index.php”,它将运行,因此如果您使用 appache 编写您的 url,则需要添加模块重写这个前缀

回答by Pankaj Kumar

Make sure you have mod_rewrite enabled in Apache .

确保您在 Apache 中启用了 mod_rewrite。

回答by Ongwaez John

For me i enabled the mod_rewrite and it worked for me well. Enable mod_rewrite for Apache: cd /etc/apache2/sites-available/ sudo a2enmod rewrite

对我来说,我启用了 mod_rewrite 并且它对我很有效。为 Apache 启用 mod_rewrite: cd /etc/apache2/sites-available/ sudo a2enmod rewrite