HI ,
In my project i am using a code like
<a href="profile.php?id=12"> Profile </a>
Once the user clicks on this "Profile" then it will be redirected to page called profile.php. And the URL will be
http://localhost/Talent/profile.php?id=12.
Now the requirement is , When the user clicks on "Profile" link , then it should go to the page
profile.php but the URL should be
http://localhost/Talent/profile.php/myname
myname is the correspond to id 12.
Please tell me , how will i do this...
URL - Redirect Using .htaccess
Moderator: General Moderators
-
BornForCode
- Forum Contributor
- Posts: 147
- Joined: Mon Feb 11, 2008 1:56 am
Re: URL - Redirect Using .htaccess
Replace with what you need
Code: Select all
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1
The following example will rewrite the product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls product.php?id=5 automatically.
Re: URL - Redirect Using .htaccess
I tried with this ... But it is not working... 
Re: URL - Redirect Using .htaccess
There are a few possible issues that could be causing this. Start eliminating them by running a phpinfo call, to get a load of info about your system.
Create a file called "phpinfo.php" (you can call it something else if you like) and put this code into it:
chmod the file to 755 to make sure it's executable and then run it, a screen of info should appear.
Possibilities, one-by-one:
Where are you hosting, on what server and is it shared, cloud, or a server(including VPS).
Owen
Create a file called "phpinfo.php" (you can call it something else if you like) and put this code into it:
Code: Select all
<?php
phpinfo();
?>
Possibilities, one-by-one:
- If you see nothing, or an error message, php isn't working properly, this is unlikely.
- Check the file for the web server running on the server, if you see apache, this is fine, if you see anything else, you may need to use slightly different syntax for your rewrite
- Check the file for the words 'mod_rewrite'. If they aren't present then your system doesn't have mod-rewrite installed anyway and this is your issue.
Where are you hosting, on what server and is it shared, cloud, or a server(including VPS).
Owen
Re: URL - Redirect Using .htaccess
Actually, scrub a lot of that, I just realised that the id you want to redirect to is *different* to the numeric id you originally used.
I.e. You want to redirect /profile.php?id=12 to /profile.php/name. You need to code this into your php. Mod-rewrite can redirect /profile.php?id=12 to /profile.php/12 but it can't look up which name corresponds to the id 12.
You need to write a function to query your DB to match a profile to a name, and include code in the profile.php file to use the query string to query this.
Second time I've written something like this today, but be REALLY careful when passing things from a URL to a database query. The potential for cracking is vastly increased.
Owen
I.e. You want to redirect /profile.php?id=12 to /profile.php/name. You need to code this into your php. Mod-rewrite can redirect /profile.php?id=12 to /profile.php/12 but it can't look up which name corresponds to the id 12.
You need to write a function to query your DB to match a profile to a name, and include code in the profile.php file to use the query string to query this.
Second time I've written something like this today, but be REALLY careful when passing things from a URL to a database query. The potential for cracking is vastly increased.
Owen