I agree with David Pashley - this is a somewhat vague question.
However I'm going to take a guess from looking at the question tags that you're using Apache as your webserver. In which case you will want to explore Mod_Rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html and modify either your Httpd.conf or .htaccess files to manipulate url rewrites.
If you're using Lighttpd you would want to look at http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModRewrite
There are still a lot of 'ifs' in your question you might want to elaborate on. Some web frameworks will handle this for you (Rails, Django, CakePHP, etc.)