TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

PHP Built-in Server: How to stop URL rewrites to index.php?

1 点作者 pyeri12 个月前
So I&#x27;m using the built-in PHP server for local development and testing:<p><pre><code> php -S localhost:8080 </code></pre> One major eccentricity or &quot;bug&quot; of this built-in server is that it not only treats index.php as the default page but also &quot;rewrites&quot; any URL paths to that page. That means when I type `http:&#x2F;&#x2F;localhost:8080&#x2F;foo&#x2F;bar`, it shouldn&#x27;t open anything as there is no `&#x2F;foo&#x2F;bar` directory structure. Instead, it causes the &#x2F;foo&#x2F;bar to be rewritten to my index.php so that the URL actually becomes `http:&#x2F;&#x2F;localhost:8080&#x2F;index.php&#x2F;foo&#x2F;bar`.<p>On a production server, this won&#x27;t happen unless you add an apache rule in the .htaccess file. So this creates obvious problems sometimes for reproducing a live issue as local testing goes smoothly whereas the app won&#x27;t work on production. Is there a way to make the built-in server stop redirecting every request to index.php and behave just like apache or nginx server?

1 comment

torunar12 个月前
1) If I understood your question correctly, you might want to use a router script for such cases: <a href="https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;features.commandline.webserver.php" rel="nofollow">https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;features.commandline.webserver...</a> (see Example #3).<p>2) For the love of god, don’t use built-in server for production cases. It’s mentioned multiple times in the documentation for a reason.
评论 #40520813 未加载