Re: Preserving URL after redirect?
| From: | Shawn McKenzie | Date: | Wed, 05 Mar 2008 18:34:01 +0000 |
| Subject: | Re: Preserving URL after redirect? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271043@lists.php.net to get a copy of this message | ||
Skip Evans wrote:
> Hey all,
>
> I have a weird issue that's got me pretty stumped, and I'm not sure I
> can do what the client is asking, or at least not how I'm trying to do it.
>
> I have a code base of my own I'm building sites on, fully AJAX enabled
> so that once the site loads it never fully refreshes a page, but AJAX
> runs everything through JS to server calls for content, updating only
> sections of the page only when needed, say for like the small calendar
> in the upper right corner when a new month is clicked.
>
> The site is basically a CMS for school sports teams to create their own
> pages, and the schools are accessed via individual directories like
>
> http://prepcube.com/wi/madison/
>
> So I created the wi/madison/
>
> ...directory when the school signs up and placed a file there that
> parses the URI to get the schools "shortname", in this case "madison",
> and then sets a session variables for school ID that allows the user to
> access this school's data.
>
> Then it redirects back to
>
> http://prepcube.com/
>
> ...which of course loses the wi/madison portion of the URL, thought the
> client wants this preserved and to remain in the URL field.
>
> And since this is a fully AJAX enables site, the URL in the browser's
> URL field would never change from
>
> http://prepcube.com/wi/madison/
>
> ...which is something the client really likes.
>
> So, my question is how would I do that, and I strongly suspect if it's
> possible at all an .htaccess file with the proper entries would be the
> way to do it, not using PHP code to redirect as I am now.
>
> Is this the case?
>
> Unfortunately, I must confess to not being terribly familiar with
> htaccess files, I believe this would be rewrite rules to rewrite the URL
> and point it to the right place? But even with htaccess rewrite rules
> could this be done to preserve the full URL with state/school in the
> browser's URL field?
>
> Any advice, as always, is greatly appreciated.
>
> Thanks globules!
> Skip
Why create a "real" directory and put a file in it? Here is one approach:
Client uses http://prepcube.com/wi/madison/ and
.htaccess rewrites to
http://prepcube.com/index.php?path=wi/madison
index.php parses the path var to extract the short name and set the
session var:
Rewrite rule would look something like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?path=$1 [QSA,L]
</IfModule>
-Shawn