Page 1 of 1

URL Display Problem - Search Engine Trick

Posted: Sat Nov 01, 2003 12:10 pm
by fireineyes
I used the URL trick of the article http://www.phpbuilder.com/columns/tim20000526.php3. In that article, he explains how to force a php script without a .php extension to run using the htaccess file. Then the variables are processed to make the url a more search engine friendly one. Example. Instead of http://www.localhost.com/local.php?coun ... Birmingham , a url would say http://www.localhost.com/local/US/AL/Birmingham thus making it look like a static page.

Now to do this he explodes the URL to get the variable out. What I want to do is change the separating character from a slash to a dash (-). The reason being, is because of a discussion I had with a SEO company that said that webpages that appear in the root directory or next one up, will have a better chance at high rankings. Any I want my url to look like this instead...

http://www.localhost.com/local-US-AL-Birmingham

That way, it appears to be a root level page. I would also (not essential to take it this far, but would be even better) like to make the Birmingham variable say Birmingham.htm in my MYSQL data table.
http://www.localhost.com/local-US-AL-Birmingham.htm

Any ideas on this, php programmers? I am new to this stuff and I tried to add the - and could not get it to read... Here is what I tried in the file that is named 'local' ... (the '/' works but '-' doesn't so far)...

Code: Select all

<?php

<?php 
$url_array=explode("-",$REQUEST_URI); //BREAK UP THE URL PATH 
// was USING '/' as delimiter changed to '-' but no luck
$url_category=$url_array[2]; //Which country? 
$url_subcategory=$url_array[3]; //Which state? 
$url_product=$url_array[4]; //Which Major City ? 

if($url_product) { 
include('include/city.inc'); 
exit; 
} elseif ($url_subcategory) { 
include('include/state.inc'); 
exit; 
} 
elseif ($url_category) { 
include('include/country.inc'); 
exit; 
} 
else { 
Header ( "Location: index.html"); 
exit; 
} 
?>
?>

Posted: Sat Nov 01, 2003 1:24 pm
by Gen-ik
What does your .htaccess file look it?

Posted: Sat Nov 01, 2003 2:30 pm
by RTT
You're however that arrays start at 0 and not 1.

The following (updated extract) should work:

Code: Select all

$url_array=explode("-",$REQUEST_URI); //BREAK UP THE URL PATH
// was USING '/' as delimiter changed to '-' but no luck
$url_category=$url_array[1]; //Which country?
$url_subcategory=$url_array[2]; //Which state?
$url_product=$url_array[3]; //Which Major City ?
and by the way, the following is better code -

Code: Select all

<?php
$url_array=explode("-", $_SERVER['REQUEST_URI']); //BREAK UP THE URL PATH

if($url_array[3]) {
    include('include/city.inc');
    exit;
} elseif ($url_array[2]) {
    include('include/state.inc');
    exit;
}
elseif ($url_array[1]) {
    include('include/country.inc');
    exit;
}
else {
    Header ( "Location: index.html");
    exit;
}
?>
edit -

on second thoughts, the '-' might not work afterall (still, your arrays were incorrect). The reason being that apache/whatever will see http://domain.com/[b]blah-blah-blah.html[/b] as a file.

When you do the '/' trick, you're essentially doing this-
http://domain.com/file.php?/some/vars/here
and so apache/whatever will understand that the slashes are part of a variable string, not anything to do with directories.

Try http://domain.com/local[b]?[/b]-blah-blah-blah.htm

:)