doumowu7371 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.

EDIT

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.

  • 写回答

2条回答 默认 最新

  • doufa5001 2017-10-30 09:16
    关注

    PHP's internal server does not recognize .htaccess files. That is a privilege of using Apache server.

    The redirects must be a part of your PHP application to retain them across all platforms.

    With PHP internal server, you can run it with a PHP file parameter.

    If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.

    PHP -S localserver:8000 router.php
    

    The script could then replace the htaccess file checking and "routing" requests to lessons/.

    For more complex applications I would suggest using a "real" webserver such as Apache or nginx as the built-in server has more limitations, such as hanging on external HTTP requests, as it is only single threaded.

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

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题