Manoaj J Rathore
Manoaj J Rathore

Reputation: 127

url routing in core php

This is my URL. I want it to change the URL via routing.https://www.example.com/view_retailer.php?rid=665 I want it to some thing like this. http://example.com/coupons-deals-cashback/AutoZone

Please help, How i can achieve this. I am using PHP as a language and i want other part of website remain intact with this functionality.

Upvotes: 0

Views: 2138

Answers (2)

user2401931
user2401931

Reputation:

There is a code that converts the perimeters in query string to variables. 1st variables will be page, 2nd will be s and 3rd will be 0. You don't have to use query strings in your URL now but you can check the requsted parameters by doing

echo "<pre>";
print_r($_REQUEST);
echo "</pre>";

.htaccess

RewriteEngine On

DirectoryIndex index.php

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L]

RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)?$ index\.php?page=$1&s=$2 [L]

RewriteRule ^([a-zA-Z0-9_-]{3,20})/?$ index\.php?page=$1 [L]

RewriteRule ^([a-zA-Z0-9_-]{3,20})?$ index\.php?page=$1 [L]

ErrorDocument 404 /404

Upvotes: 2

Borniet
Borniet

Reputation: 3546

This needs to be done in your .htaccess file of your apache webserver, or the rewriting rules of whichever other webserver you use.

Upvotes: 1

Related Questions