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
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
Share on other sites

Sorry didn't realize the bold didn't work inside the code.  You can alter the order like so:

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

 

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.