dragon321723 2015-03-04 21:50
浏览 38
已采纳

如何使用mod_rewrite伪造路径? 基本上如何使用mod_rewrite在特定的url路径上提供平面文件?

It's been awhile since I've used mod_rewrite so I am hoping somebody can shed some light on this quickly.

Basically, I have a flat dynamic PHP file, call it myForm.php. I need to serve this file whenever a request is made on the domain at the path h.t.t.tp://mydomain.com/mylong/uri/contact/path. If a user goes to that location I need my apache server to serve the myForm.php file, and this of course should be oblivious to the user. They would still see /mylong/uri/contact/path as their location address, but the file being served is from the webroot folder or some other location and called myForm.php.

This is easily possible using mod_rewrite correct?

Something like:

RewriteEngine  on
RewriteRule    ^/mylong/uri/contact/path$  /myForm.php [PT]

Does that work? Taken from: http://httpd.apache.org/docs/trunk/rewrite/remapping.html

Thanks in advance to anyone who can confirm and provide a great answer!

  • 写回答

1条回答 默认 最新

  • dquh37673 2015-03-04 22:07
    关注

    Remove leading slash from RewriteRule:

    RewriteEngine  on
    RewriteRule ^mylong/uri/contact/path/?$ /myForm.php [L,NC]
    

    .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python