【问题标题】:The url requested was not found laravel 4未找到请求的网址 laravel 4
【发布时间】:2014-06-23 09:35:11
【问题描述】:

我正在尝试使用 laravel 4 创建一个应用程序,但我遇到了 url 问题。我在我的机器上安装了 wamp。我用这段代码在我的 httpd-vhost.conf 中设置了一个新的虚拟主机

<VirtualHost mobile.dev>  
DocumentRoot "C:\wamp\www\mobile.dev\public"
ServerName mobile.dev

<Directory "C:\wamp\www\mobile.dev">
    Options FollowSymLinks Indexes
    AllowOverride All                  
    Order deny,allow
    Allow from 127.0.0.1
    Deny from all
    Require all granted     
</Directory>

mobile.dev 是一个文件夹,也是我本地主机中的域名。 这是我的 Route.php 文件

Route::get('/','HomeController@showWelcome');


Route::post('login','LoginController@userLogin');

Route::get('login','LoginController@getUsers');

当我询问 mobile.dev/login 时,它给了我未找到请求的 url。 你能帮我解决这个问题吗?但是当我要求 mobile.dev/ 它的工作时。

这是我的 .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 内容时,默认 url http://mobile.dev/index.php/login 一切正常 所以问题出在我的 htaccess 和我的虚拟主机中的重写

【问题讨论】:

  • 显示您的路线文件
  • 问题Route::get('/','HomeController@showWelcome'); Route::post('login','LoginController@userLogin()'); Route::get('login','LoginController@getUsers()');
  • 为什么routes.php 中的方法名称后面有括号 ?更具体地说,LoginController@userLogin().
  • Route::get('/' ,'HomeController@showWelcome'); Route::post('login' ,'LoginController@userLogin'); Route::get('login' ,'LoginController@getUsers'); 这不起作用
  • @Yazid 抱歉,没看到 :)

标签: php apache .htaccess laravel-4


【解决方案1】:

这可能不是 Laravel 的问题,但您的 wamp 服务器似乎尚未在 httpd.conf 文件中启用 mod_rewrite。定位线-

#LoadModule rewrite_module modules/mod_rewrite.so

并删除注释符号“#”。然后保存文件并重新启动 Apache。

【讨论】:

  • 谢谢!这解决了我在 Windows 上全新安装 Apache Server 的问题。
【解决方案2】:

解决方案: 1-当你的机器上安装了 wamp 时,请转到C:\wamp\bin\apache\Apache*.*.*\conf\httpd.conf 并确保通过删除哈希标签启用 rewrite_mod。 (而不是使用wamp提供的接口)

2-有两种方法可以在.htaccess文件中为laravel启用重写:

<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>

或使用这个:

Options +FollowSymLinks
RewriteEngine On

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

3- 如果您要设置虚拟主机,请务必在 &lt;virtualhost&gt; 标记中添加此选项

 <Directory "C:\wamp\www\mobile.dev\public">
            Options FollowSymLinks Indexes Multiviews
            AllowOverride All  
   </Directory>

非常感谢您的宝贵时间。

【讨论】:

    【解决方案3】:

    您在配置中的&lt;Directory "C:\wamp\www\mobile.dev"&gt; 应该是&lt;Directory "C:\wamp\www\mobile.dev\public"&gt; 以将公共目录指定到htaccess 重写规则的根目录。

    我最初以为您在 .htaccess 文件末尾缺少 &lt;/IfModule&gt;,但当我发布 .htaccess 文件时,它也隐藏了 &lt;/IfModule&gt;,这是堆栈溢出问题。否则你的 htaccess 是正确的。

    【讨论】:

    • 感谢您的回复。我多次更改此选项但没有成功。我在问之前就做了。
    【解决方案4】:

    你试过了吗

    Route::post('login','LoginController@userLogin');
    

    userLogin 后面没有 ()?

    【讨论】:

    • 是的,我正在使用它。这只是写问题时的一个错误。
    • 好的,所以当您访问 mobile.dev 时,您会看到您网站的主页。你有你的控制器文件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2013-10-20
    • 2015-09-14
    • 2013-09-08
    • 1970-01-01
    相关资源
    最近更新 更多