如何用 mod_rewrite 伪造路径?基本上如何使用 mod_rewrite 在特定 url 路径上提供平面文件?
How to fake a path with mod_rewrite? Basically how to serve a flat file on a specific url path using mod_rewrite?
自从我使用 mod_rewrite 以来已经有一段时间了,所以我希望有人能快速阐明这一点。
基本上,我有一个平面动态 PHP 文件,称之为 myForm.php。每当在路径 h.t.t.tp://mydomain.com/mylong/uri/contact/path 上的域上发出请求时,我都需要提供此文件。如果用户转到该位置,我需要我的 apache 服务器为 myForm.php 文件提供服务,当然用户应该不会注意到这一点。他们仍然会看到 /mylong/uri/contact/path 作为他们的位置地址,但所提供的文件来自 webroot 文件夹或其他某个位置,名为 myForm.php 。
这很容易使用 mod_rewrite 对吗?
类似于:
RewriteEngine on
RewriteRule ^/mylong/uri/contact/path$ /myForm.php [PT]
这有用吗?摘自:
http://httpd.apache.org/docs/trunk/rewrite/remapping.html
提前感谢任何可以确认并提供很好答案的人!
从 RewriteRule
中删除前导斜线:
RewriteEngine on
RewriteRule ^mylong/uri/contact/path/?$ /myForm.php [L,NC]
.htaccess
是每个目录指令,Apache 从 RewriteRule
URI 模式中去除当前目录路径(因此前导斜线)。
自从我使用 mod_rewrite 以来已经有一段时间了,所以我希望有人能快速阐明这一点。
基本上,我有一个平面动态 PHP 文件,称之为 myForm.php。每当在路径 h.t.t.tp://mydomain.com/mylong/uri/contact/path 上的域上发出请求时,我都需要提供此文件。如果用户转到该位置,我需要我的 apache 服务器为 myForm.php 文件提供服务,当然用户应该不会注意到这一点。他们仍然会看到 /mylong/uri/contact/path 作为他们的位置地址,但所提供的文件来自 webroot 文件夹或其他某个位置,名为 myForm.php 。
这很容易使用 mod_rewrite 对吗?
类似于:
RewriteEngine on
RewriteRule ^/mylong/uri/contact/path$ /myForm.php [PT]
这有用吗?摘自: http://httpd.apache.org/docs/trunk/rewrite/remapping.html
提前感谢任何可以确认并提供很好答案的人!
从 RewriteRule
中删除前导斜线:
RewriteEngine on
RewriteRule ^mylong/uri/contact/path/?$ /myForm.php [L,NC]
.htaccess
是每个目录指令,Apache 从 RewriteRule
URI 模式中去除当前目录路径(因此前导斜线)。