【问题标题】:The requested URL /ProjectName/users was not found on this server. Laravel在此服务器上找不到请求的 URL /ProjectName/users。拉拉维尔
【发布时间】:2014-02-22 20:23:36
【问题描述】:

我正在关注 laravel 的快速入门,它说 "type /users" 但不适合我。 我在浏览器中写了http://DomainServer/ProjectName/users,它会抛出:

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

我尝试了以下,

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

【问题讨论】:

  • 请将这些行粘贴到您的.htaccess 文件中

标签: php laravel


【解决方案1】:

在我的情况下,我想将此路由作为未验证用户。 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.106IPv4 地址之一)。然后就可以了。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

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

      然后在不更改DocumentRoot的情况下重新启动apache即可工作。

      【讨论】:

        【解决方案4】:

        确保您在 Apache 中启用了 mod_rewrite。

        【讨论】:

        • 谢谢Pankaj,。这应该是首先要检查的。
        【解决方案5】:

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

        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 ^(.*)/$ /$1 [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 将在您的浏览器中运行。

        【讨论】:

        • /etc/httpd/conf/httpd.conf 这在我的服务器上不存在...我应该自己创建它并按照说明操作吗?请帮忙
        • Mac 用户好吗?
        • 在 Debian 上,httpd.conf 文件是 /etc/apache2/apache2.conf;否则这些说明是正确的!
        • windows有这样的解决方案吗?
        • nginx服务器呢?
        【解决方案6】:

        首先在你的 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 文件必须在你项目的同一个文件夹中

        【讨论】:

          【解决方案7】:

          如果你尝试,默认url在你的页面前有一个前缀“index.php”.../public/index.php/your_page它会运行,所以如果你使用appache编写,你需要添加模块rewrite你的网址没有这个前缀

          【讨论】:

          • 这个“答案”让我意识到这是我的问题。只是为了扩展它,如果你认为你应该能够做类似http://DomainServer/ProjectName/users 的事情,但这不起作用,试试http://DomainServer/ProjectName/index.php/users(或者http://DomainServer/ProjectName/public/index.php/users)。如果这有效,那么您就有了上面的答案可以解决的问题!
          【解决方案8】:

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

          【讨论】:

            猜你喜欢
            • 2020-12-12
            • 2016-06-22
            • 1970-01-01
            • 2017-03-21
            • 2010-10-16
            • 1970-01-01
            • 2017-09-09
            • 2017-12-26
            • 2015-03-30
            相关资源
            最近更新 更多