View Single Post
Old 09-07-2007, 09:52 AM   #5 (permalink)
bluesaga
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

What you are looking for, my friend is Mod Rewrite, this is not PHP, however it is DIRECTLY related, a lot of applications use this facility.

To do what you want to do you would have something like:
Code:
	RewriteEngine on
	RewriteRule ^site/?$ site.php [L]
	RewriteRule ^site/([^\/]+)/$ site.php?szSite=$1 [L]
Now then if we break that down:

Code:
RewriteEngine on
Enables Mod Rewrite.

Code:
	RewriteRule ^site/?$ site.php [L]
RewriteRule is the standard prefix, the next part is a standard regular expression pattern, the next bit, is the location of the page to direct the user to. The "[L]" means "last rule", which you should use on all one line mod rewrites, it is only used for much more complicated rules.

Code:
	RewriteRule ^site/([^\/]+)/$ site.php?szSite=$1 [L]
Again RewriteRule is the standard prefix, the next part is a standard regular expression, everything within the regular expression that is located within ()'s can be used within the rule to direct the user to, in numerical order they are found. So for the next part it redirects the user to site.php?szSite=$1 The $1 looks back for what is located within the ()'s.

Now lets add an example:
I try to go to www.domain.com/site/abc/ the rewrite rule will allow me to use www.domain.com/site.php?szSite=abc without me knowing that i am actually using that page, the browser will only ever display www.domain.com/site/abc/ and the user/search engine can not find out what url they are actually viewing unless they are told, or you redirect them there mistakenly.
bluesaga is offline  
Reply With Quote