laravel 在此服务器上找不到请求的 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28242495/
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-09-08 16:51:09  来源:igfitidea点击:

laravel the requested url was not found on this server

apacheubuntularavellaravel-4

提问by user1012181

I've an Ubuntu 14.04 kernel. I was installing my Laravel application in this server. After installing, I tried to set the root directory to public.

我有一个 Ubuntu 14.04 内核。我正在这台服务器上安装我的 Laravel 应用程序。安装后,我尝试将根目录设置为public。

sudo nano /etc/apache2/sites-available/000-default.conf

I have only these options in the file

我在文件中只有这些选项

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port t$
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/public/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I've changed the Document root to

我已将文档根目录更改为

DocumentRoot /var/www/html/public/

Now when I tried to access my Laravel App, through 123.xxx.xxx.xxx/it shows the home page and working well. It gets all the GET variable too. Eg: 123.xxx.xxx.xxx?type=wefwef

现在,当我尝试访问我的 Laravel 应用程序时,通过123.xxx.xxx.xxx/它显示主页并且运行良好。它也获取所有 GET 变量。例如:123.xxx.xxx.xxx?type=wefwef

But when I go to other links such as 123.xxx.xxx.xxx/loginit gives me an error

但是当我转到其他链接时,例如123.xxx.xxx.xxx/login它给了我一个错误

Not Found

The requested URL /login/ was not found on this server.

Apache/2.4.7 (Ubuntu) Server at 104.236.234.85 Port 80

I have the routes.php working well on localhost. But not on this server. Please help me.

我的 routes.php 在本地主机上运行良好。但不是在这台服务器上。请帮我。

回答by lukasgeiter

This looks like you have to enable .htaccessby adding this to your vhost:

看起来您必须.htaccess通过将其添加到您的虚拟主机来启用:

<Directory /var/www/html/public/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

If that doesn't work, make sure you have mod_rewriteenabled.

如果这不起作用,请确保您已启用mod_rewrite

Don't forget to restart apache after making the changes! (service apache2 restart)

更改后不要忘记重新启动 apache!( service apache2 restart)

回答by Lucas Coelho

I resolved by doing the following: Check if there is a module called rewrite.load in your apache at:

我通过执行以下操作解决了:检查您的 apache 中是否有一个名为 rewrite.load 的模块:

cd /etc/apache2/mods-enabled/

If it does not exist execute the following excerpt:

如果它不存在,请执行以下摘录:

sudo a2enmod rewrite

Otherwise, change the Apache configuration file to consolidate use of the "friendly URL".

否则,更改 Apache 配置文件以整合“友好 URL”的使用。

sudo nano /etc/apache2/apache2.conf

Find the following code inside the editor:

在编辑器中找到以下代码:

<Directory /var/www/> 
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory> 

Change to:

改成:

<Directory /var/www/> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

After that restart the Apache server via:

之后通过以下方式重新启动Apache服务器:

sudo /etc/init.d/apache2 restart

回答by Mathesh Raj

First enable a2enmod rewritenext restart the apache

先启用再a2enmod rewrite重启apache

/etc/init.d/apache2 restart

click here for answer these question

点击这里回答这些问题

回答by F KIng

Alternatively you could replace all the contents in your .htaccess file

或者,您可以替换 .htaccess 文件中的所有内容

Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

See the docs here. https://laravel.com/docs/5.8/installation#web-server-configuration

请参阅此处的文档。 https://laravel.com/docs/5.8/installation#web-server-configuration

回答by croppio.com

In addition to all the answers if you still encounter some variation of the problem, edit the .envfile and set APP_URLto your domain name as in:

除了所有答案之外,如果您仍然遇到问题的某些变体,请编辑.env文件并将其设置APP_URL为您的域名,如下所示:

 APP_URL=similar_to_my_avatar_link 

回答by Masum billah

In httpd.conf file you need to remove #

在 httpd.conf 文件中,您需要删除 #

#LoadModule rewrite_module modules/mod_rewrite.so

after removing # line will look like this:

删除 # 行后将如下所示:

LoadModule rewrite_module modules/mod_rewrite.so

And Apache restart

和 Apache 重启

回答by Ahmed khaled

too late.. but for the benefit you can edit your .htaccess file comment this line

太晚了……但为了好处,你可以编辑你的 .htaccess 文件注释这一行

  #  RewriteRule ^ index.php [L]

回答by villageek

For Ubunutu 18.04 inside a vagrant box ... This is what helped me

对于流浪盒子内的 Ubunutu 18.04 ......这对我有帮助

  1. Ensure www-data has permissions to the .htaccess file

      
        sudo chown www-data.www-data .htaccess
      
    
  2. edit the apache2 conf to allow for symlinks etc

      
        sudo nano /etc/apache2/apache2.conf
      
    

    Add this to the file

  1. 确保 www-data 对 .htaccess 文件有权限

      
        sudo chown www-data.www-data .htaccess
      
    
  2. 编辑 apache2 conf 以允许符号链接等

      
        sudo nano /etc/apache2/apache2.conf
      
    

    将此添加到文件中

<Directory /var/www/html/>
  Options Indexes FollowSymLinks
  AllowOverride all
  Require all granted
</Directory>

  1. Restart your apache2 server

    sudo service apache2 restart
  1. 重启你的 apache2 服务器

    sudo service apache2 restart

I hope this helps someone.

我希望这可以帮助别人。

回答by Miguel Avila R.

Make sure you have mod_rewriteenabled.

确保您已启用mod_rewrite

restart apache

and clear cookiesof your browser for read again at .htaccess

并清除浏览器的cookie以在.htaccess 中再次阅读

回答by Abhishek Tripathi

For those who are running directly on the httpd.service of Redhat server to enable .htaccess to control the access can follow the below steps.

对于直接运行在Redhat服务器的httpd.service上启用.htaccess控制访问的可以按照以下步骤操作。

Execute the below command.

执行以下命令。

sudo vim /etc/httpd/conf/httpd.conf

Edit the httpd.conf file there is a section available with the following information

编辑 httpd.conf 文件,有一个包含以下信息的部分

<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted
</Directory> 

Change it to

将其更改为

<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory> 

Then restart the server. You can run the following commands for it.

然后重启服务器。您可以为其运行以下命令。

sudo apachectl restart

or

或者

sudo systemctl restart httpd.service