3

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

Qaisar Satti
  • 2,742
  • 2
  • 18
  • 36
Sobia Safdar
  • 83
  • 1
  • 8

4 Answers4

0

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.

Federico
  • 1,231
  • 9
  • 13
0

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

Abhinav
  • 8,028
  • 12
  • 48
  • 89
0

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.

Community
  • 1
  • 1
Abey
  • 1,408
  • 11
  • 26
0

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.

Crazy4Php
  • 246
  • 1
  • 5