doumalu9257 2015-12-19 17:45
浏览 77
已采纳

无法在Laravel框架中路由

I create an app with Laravel framework in PHP.

I have a problem with routing.

.htaccess file looks like this:

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

routes.php:

<?php
get('/', function () {
return view('welcome');
});


get('1', function() { return 'Je suis la page 1 !'; });
get('2', function() { return 'Je suis la page 2 !'; });

When I load http://localhost:63342/game/public/, server loads welcome.blade.php file, so it's okey. But when I want to load http://localhost:63342/game/public/1, I got error: 404 Not Found. I use appache server and I already enabled 'mod_rewrite' action. What can be problem?

  • 写回答

2条回答 默认 最新

  • douxian9010 2015-12-20 10:25
    关注

    I found solution. I enabled mod_rewrite action for apache server in httpd.conf, but problem was, that I didn't set correct directory path in this file for my projects.

    It should have looked like this:

    DocumentRoot "/Applications/MAMP/htdocs"
    
    <Directory "/Applications/MAMP/htdocs" >
        Options Indexes FollowSymLinks
        AllowOverride All 
    </Directory>
    

    Hope, it helps someone in future.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图