I’m trying to do something that I think should be simple, but I can’t get it to work…
I want to set up my .htaccess file so that any requests to a directory (or to any file within that directory or subdirectory) will actually return a file in a different directory.
In other words, any of the following requests (with or without query parameters):
/dummy
/dummy/
/dummy/foo
/dummy/foo/
/dummy/bar.html
/dummy/foo/bar.html
/dummy/abc/def/ghi/jkl/boo.txt
should all return the file at
/testing/test.php
Note that the /dummy directory doesn’t actually exist at all.
Ideally, it shouldn’t be possible to return the /testing/test.php file directly, but that’s not a dealbreaker. However, if query parameters are included in the original request, then they should be passed to /testing/test.php. It would be great if the PHP code in /testing/test.php could determine what the original request URI was, but that’s really a separate PHP question.
I found a similar question at Using Apache mod_rewrite to send all requests to a file which linked to Create blog post links similar to a folder structure, but I can’t seem to get it to work in my case, even though I’ve been playing with the assorted directory values.
2
Answers
Possibly something like this
You may use these rules in site root .htaccess:
Note that query string in original request will automatically be forwarded to
/testing/test.php
. Also you can get original request URI using php variable: