简体   繁体   中英

How to fake a path with mod_rewrite? Basically how to serve a flat file on a specific url path using mod_rewrite?

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 htttp://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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM