FW: [PHP] Ensuring all links go to index.php
| From: | Edward Kay | Date: | Fri, 20 Oct 2006 08:19:48 +0000 |
| Subject: | FW: [PHP] Ensuring all links go to index.php | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-243380@lists.php.net to get a copy of this message | ||
> PHP List,
>
> This problem is a little hard to describe. Please forgive me in advance
> if it's not clear.
>
> I have set up my .htaccess file to work with my PHP script to create
> "friendly URLs".
>
> For example, the URL mysite.com/user/login will take the user to a page
> where a user logs in.
>
> It does this by stripping everything out except "user" and "login". It
> takes "user" and creates a "user" object, and then passes a
> "login"
> method to that class to take the user to the login page.
>
> Somehow, in this process, the local URL is becoming "mysite/user", even
> though I'm just using that "user" designation to drive the creation of
> objects from classes.
>
> So, for example, I have a link to logout which is simply
> href="user/logout".
>
> But when I mouse over it, and look at the status bar at the bottom of my
> FireFox browser window, it says that the link points to:
> mysite.com/user/user/logout
>
> That URL, obviously, doesn't work for my system. It tries to make a
> "User" object and call a "user" method which doesn't exist.
>
> So... my question is, why is the /user portion of my URL being retained
> as a directory?
If the URL is as you describe, this should be href="/user/logout". Without the preceeding
slash, this will only work from pages with a URL in the root of your site.
>
> I thought it had something to do with setting headers. I want everything
> to operate through the index.php file in my root directory, so I thought
> I could do that by putting this at the top of the index.php page:
>
> header("Location: /");
>
> Or:
>
> header("/local/server/www/directory/");
>
> Bottom line is, how do I ensure that all links and user requests through
> the URL end up going to the index.php in my web site's root directory?
>
If your using headers to set the location, you need to provide a full URL, inc. protocol and domain.
i.e. http://www.example.com/page.php
Edward