John Davidson

rewriting URL path with PHP

0 comments
Message:


I have found many ways of solving my problem I try many of them, some work others not. so I couldn't get the finale solution I'm looking for.


so I have a website with every restaurants in every city, cites in index page, then types, then, restaurants.


city path /sub/city.php?city=11


type path /sub/type.php?city=11&type=22


restaurants path /sub/restaurants.php?r=name


i want to be


/11
/11/22
/11/22/restaurantsName

i understand there is a way by .htaccess but nothing changes,



RewriteEngine On
RewriteRule ^(.*)$ /city.php?city=$1 [L]
RewriteRule ^/([A-Za-z0-9-]+)/$ /$2 [L]


i also tried another way by redirecting all paths to index.php and then from there i redirect each to its path, but i don't understand how to redirect them to /11 if there is no /11!



$path = ltrim($_SERVER['REQUEST_URI'], '/');
$urlarray = explode('/', $path);
print_r($urlarray);

if(!empty($urlarray[0])){
//header("Location: /index.php");
//exit();
} else if (!empty($urlarray[1])){
header("Location: /11");
//exit();
}


please help or redirect me to a solution,



My Answer:
=11&type=5_restaurant path /sub/restaurant.php?city=11&type=5&restaurant=25

I have tried using PHP to rewrite the URL path to make it more user-friendly and easier to navigate. Here is an example of how I have rewritten the URL path:

/city/11/type/5/restaurant/25

By using PHP to rewrite the URL path, I can make the website more organized and user-friendly for visitors. This way, they can easily navigate through the different cities, types, and restaurants without having to remember complex URLs with query parameters.

Rate this post

3 of 5 based on 3248 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us