Jump to content

Rewrite URL


svgmx5

Recommended Posts

i'm looking for help with rewriting a url i have....

 

 

The link i have currently looks like this:

 

domain.com/page.php?city=cityname&state=state&country=country

 

I want to make that URL look like this:

 

domain.com/countryname/statename/cityname/

 

I have included the current .httaccess that i'm using to covert other links that i have...


<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ types.php?name=$1 [L,QSA]

</IfModule>

 

This is working to convert links such as this: 'domain.com/page.php?name=name' to 'domain.com/name'

 

This work perfectly but since i have to have the city, state and country in the URL to display the correct city i want to know how i can use the .htaccess to create that.

 

Hope someone can help me

 

 

Link to comment
https://forums.phpfreaks.com/topic/237483-rewrite-url/
Share on other sites

I think something along the lines of this will do what you want:

 

Put the following ABOVE your rewrite rules & conditions:

 

RewriteBase  /

 

Then add this anywhere in your rules & conditions:

 

RewriteCond %{QUERY_STRING}             ^city=([^/]*)&state=([^/]*)&country=([^/]*)
RewriteRule   ^.*$                                    /%1/%2/%3/

 

Let me know how it works out.

Link to comment
https://forums.phpfreaks.com/topic/237483-rewrite-url/#findComment-1220432
Share on other sites

well i tried it out and i'm getting this error on the screen

 

[an error occurred while processing this directive]

 

and here's the .htaccess code i have now:

 


<IfModule mod_rewrite.c>

RewriteBase  /

RewriteEngine on
RewriteCond %{QUERY_STRING}^city=([^/]*)&state=([^/]*)&country=([^/]*)
RewriteRule   ^.*$/%1/%2/%3/

</IfModule>

 

Now i'm trying to access it by typing it the following way:

 

domain.com/locations/city/united_states/illinois/chicago

 

also...previoulsy on the actual file which is under city/index.php i have php code that looks like this

 


<?php

$city = $_GET['city'];
$state = $_GET['state'];
$country = $_GET['country'];

?>

Is there anything i should change there? 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/237483-rewrite-url/#findComment-1220461
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.