Forum Moderators: phranque
Now I want to set it up such that when someone visits www.example.com/arts/hello.php, i want them to (1) be redirected to the corresponding php file in the root but (2) the url in the browser address box should still look like www.example.com/arts/hello.php.
So while the user is actually seeing www.example.com/hello.php page, he gets the impression that he is seeing the www.example.com/arts/hello.php page.
Can someone please help me with how to do this. thanks.
It's also not "URL masking", since the URL is not changed: Only the URL-to-filepath mapping is changed, and the client doesn't know (or care) what *file* you use to satisfy its request for a *URL*.
It is a trivial mod_rewrite application, with many examples given here in this forum and our Apache Forum Library, as well as in Apache.org's on-line URL Rewriting Guide.
However, the complication comes in with this question: How does the "hello.php" script's behavior change if the request was for "/arts" as opposed to something else, and how do you intend for the "hello.php" script to 'know' that the request was for "arts" after you've rewritten the request? This is by no means a show-stopper, but you have to pick a method before you can code anything. Generally, your script can either examine a server variable to get the originally-requested URL-path, or you can code your rewrite rule to pass the originally-requested URL-path to your script as a query string name/value pair, which it must then examine.
Jim