2017-10-30 09:13
浏览 208

使用PHP -S localhost服务器时如何获得重定向工作(.htaccess)?

I used xampp in the past in order to develop websites on a local computer, but I recently found it less cumbersome to simply start a server using the PHP -S localserver:8000 where 8000 is the port number. I managed to get phpmyadmin working that way and access databases. So all was fine ... until I tried to re-use redirecting rules within a .htaccess file.

The rules work well on the my web provider's servers, but it doesn't work on localhost. I assume there's something to do in order to turn the re-write rules on but since I am not longer using xampp, I don't know if there's still something like Apache running in the background, etc. If someone has experience with this setup, I would like to know how or if this can be be done.


The redirect is basic:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule lessons/(.*)$ page.php?url=$1

And to make the question more meaningful (addressing some of the comments below), I think Finwe answered my question rightly, that is: "this doesn't work with the PHP approach, .htaccess is specific to Apache".

My question wasn't about "what alternative solution do I have". The solution I would use is probably to go through a combination of AJAX/PHP to solve the limitation but that's surely not the most straightforward workaround.

图片转代码服务由CSDN问答提供 功能建议

我过去使用xampp来开发本地计算机上的网站,但我最近发现它不那么麻烦 只需使用 PHP -S localserver:8000 </ code>启动服务器,其中 8000 </ code>是端口号。 我设法让 phpmyadmin </ code>以这种方式工作并访问数据库。 所以一切都很好......直到我尝试在 .htaccess </ code>文件中重新使用重定向规则。</ p>

规则适用于我的Web提供商的服务器 ,但它不适用于localhost。 我假设有一些事情要做,以便重新开启重写规则,但由于我不再使用xampp,我不知道是否还有像Apache一样在后台运行等等。如果有人有这种设置的经验 ,我想知道如何或是否可以这样做。</ p>

编辑</ h1>

重定向是基本的:</ p> \ n

  RewriteEngine On 
RewriteBase / 
RewriteRule lessons /(.*)$ page.php?url = $ 1 
 </ 代码> </ pre> 

为了使问题更有意义(解决下面的一些评论),我认为Finwe正确地回答了我的问题,即:“这不适用于PHP方法 ,.htaccess特定于Apache“。</ p>

我的问题不是”我有什么替代解决方案“。 我将使用的解决方案可能是通过AJAX / PHP的组合来解决限制,但这肯定不是最简单的解决方法。</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题