Warning: fopen(graphic_design/files/thread-741-1.txt) [function.fopen]: failed to open stream: Permission denied in /graphic_design/global.php on line 421
file NOT opened Search Engine/User Friendly URLS -
PDA

View Full Version : Search Engine/User Friendly URLS


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.

Koobi
05-20-2004, 11:43 AM
Sweet stuff :)
For those of you who use the newer version of Invision board, you will see something like this script there as well.

Octane
05-21-2004, 10:10 AM
however, if you are using a cgi version of php, you will need something like this in your apache config file (this one I wrote for vB3 archive to have it work like the old vb2 archive - which is much better)

RewriteRule ^/forum/archive/forum/([0-9]+).html$ /forum/archive/index.php?f=$1 [L]
RewriteRule ^/forum/archive/topic/([0-9]+).html$ /forum/archive/index.php?t=$1 [L]