Arch Stanton
04-30-2004, 12:41 PM
I think I posted something similar to this before, but this is a bit more comprehensive, and easier. However, I don't think I go into enough detail here.
Many search engines have problems with "search" urls, or urls with question marks. This script will help you get around this by removing the question mark and using an array based on a url that looks like directories.
Use the following code to make search engine friendly links to your PHP pages.
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[1];
$VariableTwo=$arrPageVars[2];
If your page is in a directory, you will need to increase the index number by one for each directory deep you page is.
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[2];
$VariableTwo=$arrPageVars[3];
Your URLS should look like this:
http://domain.com/mypage.php/One/Two/Three/Four/Five/Six
You can change any of the numbers to any value. You can easily add and edit the script for more, or less variables.
When accessing the page normally, or from a form, the url would look like this:
http://domain.com/mypage.php?var1=One&var2=Two&var3=Three&var4=Four&var5=Five&var6=Six
If you want to get even better, get you can set it up so you can name your php files without an extension.
Place a .htaccess file in your directory with the following info:
<Files mypage>
ForceType application/x-httpd-php
</files>
Where “mypage” is, place the name of your php page. Remove the .php from your page and now your urls should look like this:
http://domain.com/mypage/One/Two/Three/Four/Five/Six
If you plan to get your information from a form, you should add a check to your code to use that information instead:
If (!$HTTP_GET_VARS) {
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[1];
$ VariableTwo=$arrPageVars[2];
}
One more thing, if your apache version is greater than 2, add this to your .htaccess file
AcceptPathInfo On
There you go.
Many search engines have problems with "search" urls, or urls with question marks. This script will help you get around this by removing the question mark and using an array based on a url that looks like directories.
Use the following code to make search engine friendly links to your PHP pages.
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[1];
$VariableTwo=$arrPageVars[2];
If your page is in a directory, you will need to increase the index number by one for each directory deep you page is.
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[2];
$VariableTwo=$arrPageVars[3];
Your URLS should look like this:
http://domain.com/mypage.php/One/Two/Three/Four/Five/Six
You can change any of the numbers to any value. You can easily add and edit the script for more, or less variables.
When accessing the page normally, or from a form, the url would look like this:
http://domain.com/mypage.php?var1=One&var2=Two&var3=Three&var4=Four&var5=Five&var6=Six
If you want to get even better, get you can set it up so you can name your php files without an extension.
Place a .htaccess file in your directory with the following info:
<Files mypage>
ForceType application/x-httpd-php
</files>
Where “mypage” is, place the name of your php page. Remove the .php from your page and now your urls should look like this:
http://domain.com/mypage/One/Two/Three/Four/Five/Six
If you plan to get your information from a form, you should add a check to your code to use that information instead:
If (!$HTTP_GET_VARS) {
$arrPageVars = explode("/", $_SERVER['PATH_INFO']);
$VariableOne=$arrPageVars[1];
$ VariableTwo=$arrPageVars[2];
}
One more thing, if your apache version is greater than 2, add this to your .htaccess file
AcceptPathInfo On
There you go.