URL Rewrite without using .htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
binay00713
Forum Newbie
Posts: 1
Joined: Fri Mar 16, 2012 5:39 am

URL Rewrite without using .htaccess

Post by binay00713 »

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? :idea:
User avatar
azycraze
Forum Commoner
Posts: 56
Joined: Mon Oct 24, 2011 12:08 pm
Location: India

Re: URL Rewrite without using .htaccess

Post by azycraze »

why are you not interested in using htaccess...?????????
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: URL Rewrite without using .htaccess

Post by twinedev »

The only way you are going to do it with php only (ie, no .htaccess or modifying the conf of apache) is to make a file called index.php and place it in a directory /product/name/xzy/q/service and tell it to call /product.php?name=zyx&q=service

And you will have do this for EVERY item you want mapped over.

In short. You can't. PHP scripts can only run when they are called, so you either need an actual php file to call, or you have to do a rewrite rule to tell it to call it for set conditions.

-Greg
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: URL Rewrite without using .htaccess

Post by Eric! »

You could make a PHP file that handles 404 errors. It can then parse the requested /product/name/xyz/q/service rebuild the query string and redirect to /product.php?name=zyx&q=service

However you will have to either go into your cPanel or .htaccess to tell Apache where to find your PHP script for handling 404 errors.
Post Reply