DIGIT-ARC read-only archive · snapshot: July 23, 2026

URL Rewrite without using .htaccess

3 posts · originally from https://geek.digit.in/community/threads/url-rewrite-without-using-htaccess.154177/

B
binay00713 Original post #1
Mar 16, 2012 at 4:52 PM
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?
H
hsr #2
Mar 30, 2012 at 3:11 PM
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
nbaztec #3
Mar 30, 2012 at 9:42 PM
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.