Forum Moderators: phranque

Message Too Old, No Replies

Need help with redirect and url masking

         

barxam

8:06 am on Dec 23, 2009 (gmt 0)

10+ Year Member



Ok lets say that I have a website called www.example.com. In the root directory, I have a bunch of php pages like hello.php and byebye.php.

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.

jdMorgan

6:41 pm on Dec 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is an internal rewrite, not an external redirect.

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