Reputation: 1427
I am programming an website and I want to redirect specific URL like
www.example.org/p/home
www.example.org/p/user/th3falc0n
to my script
www.example.org/index.php?page=home
www.example.org/index.php?page=user/th3falc0n
without the user recognizing that the server is redirecting this page to the script. How can I do this?
Upvotes: 1
Views: 1103
Reputation: 276
Using .htaccess is usually the best way to approach this - it's a file which tells Apache (or your web server software) where the request should go.
Here is a previous question on this subject: help regarding dynamic redirect rule in htaccess
Answer quoted here:
http://www.abc.com/site/var1 http://www.abc.com/site/var2 That way, you can ensure you only ever apply the rule if the psuedo "site/" directory is browsed and not affect any other URI. This is the rewrite rule based on the above schema.
RewriteEngine on RewriteRule ^site/([^/.]+)/?$ index.php?u=$1 [L,NC,QSA] Any other address, other than "/site/.../" would be unaffected by this rule, which means you don't need to worry about setting some addresses to be avoided. This keeps things as simple as possible.
You don't have to use "site" - you can use whatever name fits your purpose.
Upvotes: 1
Reputation: 4568
you need .htaccess rewrite to do that - http://www.branded3.com/blogs/htaccess-mod_rewrite-ultimate-guide/
Upvotes: 3