# URL Rewrite without using .htaccess



## binay00713 (Mar 16, 2012)

Hello everyone,How can i change the url  when I am navigating from one page to another.

for example if the existing url is like "www.example.com/product.php?name=xyz&q=service" ,I want to change it to  "www.example.com/product/name/xyz/q/service"

But I dont want to use .htacces. How can I do it using php functions only?


----------



## hsr (Mar 30, 2012)

You can do it in this way, say your domain is *example.in/ and want something  like *example.in/product/name/id, the closest you can get with just PHP would be something like *example.in/product.php/name/id

Where in product.php, you should use

```
preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $urlBits)
```

$urlBits will contain an array of elements, from the example, $urlBits[0]  = 'name' and $urlBits[1] = 'id'


----------



## nbaztec (Mar 30, 2012)

Building on _hsr's reply:

you can use 

```
header("location: *example.com".preg_replace('#(.php\??)|[=&]#','/',$_SERVER['PHP_SELF']));
```

Please note that this should be before any headers are sent (like the first statement) and may change depending upon your other pages.


----------

