Forum Moderators: phranque

Message Too Old, No Replies

Redirect from directory to variable

         

hrafn

4:57 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



Does anyone know how to redirect a unknown directory to a variable in php?

example:
www.asdf.com/joe -> www.asdf.com/profile.php?user=joe
or:
www.asdf.com/$var -> www.asdf.com/profile.php?user=$var

This would have to be automatic since I'll have multible and unknown amount of users using this feature.
Also I'd like these folders to be virtual (or not actually there).
So, this should only affect directories that do not excist :)

Thank you,
Halldor Hrafn.

jdMorgan

5:57 pm on Jul 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Halldor,

Welcome to WebmasterWorld [webmasterworld.com]!

Using Apache mod_rewrite, you can add


RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_FILENAME} !-d

as conditions to a RewriteRule to detect that the requested URL does not contain "." (and is therefore not a filename) and that a directory of that name does not exist.

Our forum charter [webmasterworld.com] provides a few links to basic resources to help get you started.

Jim

hrafn

10:03 pm on Jul 29, 2004 (gmt 0)

10+ Year Member



Would it be possible to do:
www.domain.com/bob

and get redirector to a page:
www.domain.com/profile.php?user=bob

but still make it look like this to the browser:
www.domain.com/bob

(/bob is a non-excistant directory)

thanks,
Halldor Hrafn.

[edited by: jdMorgan at 10:54 pm (utc) on July 29, 2004]
[edit reason] Spliced with previous thread [/edit]

Birdman

10:12 pm on Jul 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Absolutely! Using mod_rewrite [httpd.apache.org]. See the RewriteEngine and RewriteRule sections.