URL Rewrite without using .htaccess

binay00713

Broken In
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?
 
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
Code:
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

Master KOD3R
Building on _hsr's reply:

you can use
PHP:
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.
 
Top Bottom