Let the example be
I have a link:- localhost/project/search?uni=1
I want to change it in this way:- localhost/project/search/uni-of-uk
I am not using any framework , its a core PHP
Let the example be
I have a link:- localhost/project/search?uni=1
I want to change it in this way:- localhost/project/search/uni-of-uk
I am not using any framework , its a core PHP
Like this... based on the little info you gave ....
$link = 'localhost/project/search?uni=1';
$link = str_replace('?uni=1', '/uni-of-uk', $link);
NEW: in PHP you can modify the header to change the url.
if($_GET['uni']==1)
{ header('Location: localhost/project/search/uni-of-uk');
exit;
}
The important thing is that you DO NOT OUTPUT ANITHING before you call the header function. So you should put this code on top of your script before any output.
What you are looking for is called URL Rewriting
.
You can achieve this using mod_rewrite
(assuming you are using apache).
You might want to look into this mod_rewrite Article
If you meant you want to change
localhost/project/search?uni=1
to
localhost/project/search/uni-of-uk/1
You can achieve it by creating a .htaccess in your root folder and adding something like this to it,
RewriteEngine on
RewriteRule ^/?search/uni-of-uk/([0-9]+)$ /search?uni=$1
Another method is PHP routing, big CMS sites follow this method as said here.
This can help you:
Write below code in your .htaccess file.
RewriteRule ^search/([^/]+) search.php?uni=$1 [NC]
Now, you can get value of "uni" using $_REQUEST['uni'] or $_GET['uni'] in your php file.