Jump to content

mod rewrite and php


dflow

Recommended Posts

Well, I think the simplest method is to just send all requests to the respective page, and let PHP to the parsing of the URI. You'll have to come up with a regex for that.

 

In PHP you could do something like

<?php
$uri = $_SERVER['REQUEST_URI'];
$params = explode("/", $uri);

You now have all the parts of the URI in an array. It would look something like this:

array {
            [0] => 'http:'
            [1] => ''
            [2] => 'example.com'
            [3] => 'CountryName'
            [4] => 'CityName'
}

 

You can see how with the knowledge that REQUEST_URI will always contain what the user actually requested, and not the real path to the script, you can parse the URI and get the information you want out of it.

Link to comment
https://forums.phpfreaks.com/topic/196551-mod-rewrite-and-php/#findComment-1031963
Share on other sites

RewriteRule ^(.*)/(.*)/?$ page.php?CountryID=$1&CityName=$2 [L]

 

Should work. But may not yeild the exact results you want, as anything even say example.com/sub/realdir/ will get redirected as well.

cool this works

i still have the CityID as a number

so the url looks like this

amsterdam-tourist-sites/1.html

regarding seo is this a good move

keeping the number?

Link to comment
https://forums.phpfreaks.com/topic/196551-mod-rewrite-and-php/#findComment-1031994
Share on other sites

  • 2 weeks later...

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.