Use "subdirectory" in URL as variable...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BlurryDude
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 7:44 am

Use "subdirectory" in URL as variable...

Post by BlurryDude »

I'm not sure how to word this, so I do apologize if the subject is inaccurate for this post, but I want to do the following:

Instead of this:
http://www.domain.com/?user=bob

I want to use this:
http://www.domain.com/bob

How do I do this?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Use "subdirectory" in URL as variable...

Post by pickle »

You'll have to use an .htaccess file and mod_rewrite. Something like this might work:

Code: Select all

RewriteEngine on
RewriteBase /
 
# don't rewrite if the requested file is an actual file or directory
RewriteCond %{REQUEST_FILENAME}  !-s
RewriteCond %{REQUEST_FILENAME}  !-d
 
RewriteRule ^(.*)$ http://www.domain.com/?user=$1
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
BlurryDude
Forum Newbie
Posts: 7
Joined: Wed Feb 10, 2010 7:44 am

Re: Use "subdirectory" in URL as variable...

Post by BlurryDude »

Thank you :) will this work on a Windows Server?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Use "subdirectory" in URL as variable...

Post by pickle »

Are you using Apache or IIS? mod_rewrite is only for Apache.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply