【问题标题】:Laravel 5 pretty URL not working on wampLaravel 5漂亮的URL不适用于wamp
【发布时间】:2015-07-04 17:06:10
【问题描述】:

我是 Laravel 的新手,我正在使用 wamp 处理一个小项目。我遇到了漂亮的 URL 部分的问题,我刚刚发现了。

但现在我遇到了一个奇怪的问题。我在 laravel-first-app 目录下创建了我的应用程序。 当我尝试请求一个页面(文章)时,例如 http://localhost/laravel-first-app/public/index.php/cv,它会显示该页面。

但现在,如果我请求一个页面,例如,http://localhost/laravel-first-app/public/cv,则表示 URL Not Found 错误。

以下是我所做的简要说明。

在我的 routes.php 中

Route::get('/', 'WelcomeController@index');

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);

Route::resource('articles','ArticlesController');
Route::get('articles/delete/{article_id}','ArticlesController@destroy');

Route::get('cv','CvController@index');
Route::get('cv/upload','CvController@upload');
Route::post('cv','CvController@store');

在我的 CvController 中

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class CvController extends Controller {

    private $pathToCV;
    private $fileName;

    public function __construct()
    {
        $this->pathToCV="cv/";
        $this->fileName='piyush_cv.doc';
    }
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return response()->download($this->pathToCV.$this->fileName);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function upload()
    {
        return view('cv.upload');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store(Request $request)
    {
        dd($request);
        if($request->hasFile('cv'))
        {
            $file = $request->file('cv');
            $file->move($this->pathToCV,$this->fileName);
            flash()->overlay('File Uploaded','Thanks for uploading the file');
            return redirect('cv/upload');
        }
        flash()->overlay('File was not selected','');
        return redirect('cv/upload');

    }

}

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

另外,对于我的 wamp,我启用了 mod_rewrite 模块。

你能帮我解决这个问题吗?我想使用网址 http://localhost/laravel-first-app/public/cv 而不是 http://localhost/laravel-first-app/public/index.php/cv

请帮忙。

【问题讨论】:

    标签: php laravel laravel-5


    【解决方案1】:

    转到项目文件夹,打开终端,然后运行php artisan serve,它将启动 localhost:8000 或类似的,然后只需转到 https://localhost:8000/articles 以获取所需的页面

    【讨论】:

    • 我试过了,但它没有启动 localhost:8000,终端抛出 CLI 停止工作的错误。
    • 如果你在windows中,那么你需要设置php环境变量来运行任何php命令。
    • 我在我的系统上设置了 php 环境。即使它不起作用。
    • 我得到了它的工作......我尝试了其他一些方法......无论如何谢谢@try_simple_code
    【解决方案2】:

    我仔细查看了应用程序结构,发现了问题所在。

    现在,我解决了问题,一切正常。

    在Controller CvController中,我发送了一个目录CV,路径名也是CV,所以表现很奇怪。

    如果您需要详细的解决方案,请告诉我。

    还是谢谢。

    【讨论】:

    • 你能补充一下你做了什么吗?
    猜你喜欢
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2014-01-25
    • 2013-03-14
    相关资源
    最近更新 更多