【问题标题】:root folder redirection issue in laravellaravel中的根文件夹重定向问题
【发布时间】:2019-04-10 14:49:45
【问题描述】:

我正在为 laravel 使用 wamp 服务器。 我的网址是 localhost/pjct_name/public。 我有下面给出的 ajax 网址

$.ajax({
        type: "POST",
        dataType: 'json',
        url : "../getCustomer",
        ...  
       });

它适用于编辑而不是请求

Route::get('/request', [ 
        'middleware' => 'roles',
        'roles' => [ 
                'Requestor' 
        ],   
        function(){return View('layouts.request');}
]);
/*Edit request*/
Route::get('/edit/{id}',array('as'=>'edit','middleware' => 'checksession',
        function($id){
        $data['id'] =$id;
        return View::make('layouts.request',$data);
    })
);

在请求页面重定向到http://localhost/asset/getCustomer 但我需要重定向为http://localhost/asset/public/getCustomer 如何编写 htaccess 进行重定向。 我试过了

 RewriteEngine On
 RewriteRule ^$ /public [L] 

但没有运气

【问题讨论】:

  • 使用绝对网址而不是相对网址。
  • 设置虚拟主机将是解决此问题的一种更简单的方法。

标签: php laravel laravel-5 laravel-5.3


【解决方案1】:

根据Route改变AJAX请求中的url

$.ajax({
        type: "POST",
        dataType: 'json',
        url : "/request",
        ...  
       });

同时将 web.php 中 Route 的方法从 'get' 更改为 'post'

Route::post('/request', [ 
        'middleware' => 'roles',
        'roles' => [ 
                'Requestor' 
        ],   
        function(){return View('layouts.request');}
]);

AJAX 请求成功后重定向您的页面。

success: function (response) {
    windoe.location.href = "/your-next-page";
},

希望它对你有用,

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 2014-12-09
    • 2017-08-02
    • 2015-07-13
    • 2018-05-08
    • 1970-01-01
    • 2015-09-19
    • 2014-03-30
    • 1970-01-01
    相关资源
    最近更新 更多