dqhmtpuy94946 2015-10-09 12:19
浏览 82

Laravel Rest API无法在实际服务器上运行

I am trying to create a small application that uses Laravel REST api as backend and Angular for frontend.

I've managed to display json on the browser in localhost but when I uploaded to 1and1.com server, the index page works fine but api ur such as - xyz.com/public/names gives a 404 page not found error.

My Directory structure

 empdir
      empdir-backend
         laravel
      empdir-frontend
         js
         css
         index.html

Am I missing some thing.

This is my Route.php

Route::get('/', function () {
    return view('welcome');
});

Route::get('names', function () {
    $data = array(
        1 => "John",
        2 => "Mary",
        3 => "Steven"
    );

    return view('rest', $data);
 });

Route::get('names/{id}', 'NameController@showEmpDetail');
Route::resource('names', 'NameController');

Controller.php

public function index()
{
    return array(
        1 => "John",
        2 => "Mary",
        3 => "Steven"
    );

}

.htaccess

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

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

  • 写回答

2条回答 默认 最新

  • douke1954 2015-10-09 12:22
    关注

    you need a .htaccess file with this in it: ` Options -MultiViews RewriteEngine On

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    `

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看