douang2297 2014-06-20 22:45
浏览 55
已采纳

超薄框架 - 无法解释带点的路线

Problem Statement

I'm currently working on an internal RESTful API, and I'm using our main domain name as an environment identifier. However, I noticed that Slim does not like it at all for a route to have dot in there.

Sample case

I have a local web server running using PHP's built-in webserver, and I invoked php -S 0.0.0.0:5000 to get it running.

Once the web server is up, I have a simple 'hello world' on the index page. Everything's working fine and dandy.

I then set up a route as following:

$app->get('/:domain/:id', function($domain, $id) 
{
    echo $domain . ' ' . $id;
} 

With this, I set up the route to hopefully resolve 0.0.0.0:5000/apple.com/juicers. I tried with 0.0.0.0:5000/apple/juicers and the page prints out apple juicers. But with 0.0.0.0:5000/apple.com/juicers, I get a 404 Not Found error.

What I've tried so far

URL Rewrite

I looked up the available resources on Google, and from Slim framework's Github issues as well. It seems like someone encountered a similar issue: https://github.com/codeguy/Slim/issues/359

The proposed solution in that ticket was: URL rewriting fix. I tried that but to no avail. I set up a .htaccess at the root of my project directory, and turned on AllowOverRide All in my Mac's httpd.conf file.

php -S 0.0.0.0:5000 index.php

Instead of running php -S 0.0.0.0:5000 by itself, I ran the command on index.php. At this point, instead of throwing a Not Found error, the slim framework is resolving to my base route, which I set up as follows:

$app->get('/', function() { echo "hello world"; });

Thank you

I'm at my wit's end, and any help will be highly appreciated. Thank you so much for reading!

  • 写回答

4条回答 默认 最新

  • douti9253 2014-06-25 23:06
    关注

    Root issue - PHP Development server

    After playing with different Slim conditions and experiments, I started to look closer at the server level and making sure that the URL was passed correctly to the Slim routes.

    Turns out this was an issue with PHP's development server, which is available through the php -S command.

    A quick google search revealed that several others had encountered the same issue, and it was a server issue, rather than a bug in Slim.

    Solution

    To test out my solution, I ran MAMP, and transferred all my files over. And then I wrote the .htaccess to redirect all requests through to index.php.

    The moment of truth:

    I typed in localhost:8888/campaigns/demo.com/12 and a wave of joy surged through my veins as I saw a line of beautiful, gorgeous demo.com/12 written across the browser! (I have an echo statement for that particular route) A week-plus of troubleshooting and tinkering around has finally bore fruit!

    Celebratory Hoorah!

    \(^O^)/ Hoorah for Apache!

    Thanks for your help @adosaiguas!

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了