I am having a url like
I need to change this url to
This username is taken dynamically from the database with the entry id=1064
Please advice me a solution to rewrite my url to the above format
I am having a url like
I need to change this url to
This username is taken dynamically from the database with the entry id=1064
Please advice me a solution to rewrite my url to the above format
You can use RewriteEngine on
in your .htaccess
file to add RewriteRule
s. Have a look at Mod Rewrite:
First of all, you have to have RewriteEngine on inside your .htaccess
.
RewriteEngine On
After that, you need the regular expression for your link. Supposing that all your username contains only letters and numbers, this will be the appropriate regular expression. However, if it's not the case, simply adjust the [A-z0-9]
part to whatever characters your username can have.
RewriteRule ^([A-z0-9])/?$ profile.php?username=$1 [NC,L]
Notice that we're passing the username as the $_GET param instead of the id.
Also, it's recommended to put something before the username in your link. In other words, http://example.com/u/username instead of http://example.com/username because if you have a page such as http://example.com/random, it's going to call the profile.php
with random
as the username. So for the example above, the regular expression would be:
RewriteRule ^u/([A-z0-9])/?$ profile.php?username=$1 [NC,L]