Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 除根外,Laravel路由不工作_Php_Apache_.htaccess_Laravel - Fatal编程技术网

Php 除根外,Laravel路由不工作

Php 除根外,Laravel路由不工作,php,apache,.htaccess,laravel,Php,Apache,.htaccess,Laravel,我在这个问题上花了几个小时,希望能找到出路。我已经正确设置了laravel,创建了一个项目myapp 我的route.php文件只包含 Route::get('/', function() { return View::make('hello'); }); Route::get('/users', function() { return 'Users!'; }); 当我跑的时候 http://localhost/myapp/public/ 我正确获取了laravel的起始页 当我跑

我在这个问题上花了几个小时,希望能找到出路。我已经正确设置了laravel,创建了一个项目myapp

我的route.php文件只包含

Route::get('/', function()
{
return View::make('hello');
});

Route::get('/users', function()
{
    return 'Users!';
});
当我跑的时候

http://localhost/myapp/public/
我正确获取了laravel的起始页

当我跑的时候

http://localhost/myapp/public/users
http://localhost/myapp/public/index.php/users
我明白了

我不知道为什么要找index.php

当我跑的时候

http://localhost/myapp/public/users
http://localhost/myapp/public/index.php/users
我得到一个有“用户”文本的页面。我应该在运行时获得此页面

http://localhost/myapp/public/users
相反

下面是我的.htaccess

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

    RewriteEngine On
    Rewritebase /myapp/
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

选项-多视图
重新启动发动机
重写库/myapp/
#重定向尾部斜杠。。。
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]

有什么想法吗?我在Linux上运行Apache。

在您的应用程序/config/application.php文件中更改:

'index' => 'index.php',
致:

这应该告诉laravel不要使用index.php并正确重写


它适用于laravel附带的标准.htaccess文件(未检查是否修改过)

使用此重写规则:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /my_app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

选项-多视图
重新启动发动机
重写基本/我的应用程序
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
另外,在“application/config/app.php”中,更改:

'index'=>'index.php'

'index'=>''

  • 确保在apache web服务器上启用了mod_rewrite
  • 确保vhost配置允许并解析htaccess文件

  • 您的
    RewriteBase
    设置为
    /myapp/
    ,但您的index.php文件位于
    /mayapp/public/
    中,不是吗


    因此,我认为您会发现,
    RewriteBase
    需要是
    /myapp/public/

    最快的方法是在命令行中添加一个符号链接:

    ln -s your/acutal/path/myapp/public app-dev
    

    现在浏览
    http://localhost/app-dev
    应能与所有路线一样正常工作。您可以将app dev更改为任意名称。

    只需执行此操作并尝试重新启动apache即可

    sudo a2enmod rewrite
    

    要重新启动apache:
    sudo services apache2 restart

    我在生产服务器上遇到了同样的问题,似乎什么都不起作用,没有chmod/s没有其他解决方案,只是在.htaccess中添加了一行简单的代码

    RewriteBase /
    

    多亏了线程和用户

    对您的答案进行了一点修改。RewriteBase应为/myapp,不带下划线。在我的app.php中没有索引,php条目,我只是添加了一行。现在,在该服务器上甚至找不到无法获取URL/myapp/index.php的根路径。恢复了我的.htaccess和根路径。还有其他建议吗?app.php中没有这一行。我添加了它,但仍然存在相同的问题。您使用的是laravel 3或4?请检查此项,谢谢!在我的例子中,我的Laravel应用程序在我的文件夹结构中处于较低的一个级别,但是通过明智地修改
    index.php
    条目文件,以及向
    .htaccess
    添加
    RewriteBase
    ,效果非常好。