The following script is a VERY simplified version of a script I've used to make my site more search engine friendly.

To date, according to most reports, Google is one of the only search engine that will index URLs that are in the format: whatever.com/index.php?var1=value&var2=value

Other Search Engine spiders may or will die as soon as a "?" or "&" is reached in the URL.

To get past this issue, so that your site is fully indexed by all search engines, you will need to do three things.

First:
You will need to let your Apache Server know that you want to do this.
Using the ForceType Apache Directive, you can let Apache know that the file "search", or whatever the script name will be (without .php extension), will be treated as a PHP file.

By adding the following to your httpd.conf file, you can make this happen. Just replace the directory path with your directory path to your http documnents folder.

<Directory /home/blah/domain.com/httpdocs/>
        <Files search>
                ForceType application/x-httpd-php
        </Files>
</Directory>

If you don't have access to the httpd.conf file on your web hosting server, you can create a .htaccess file with the same info, and drop it into the root of your web directory. Most web hosts will allow .htaccess files, but some won't.

Second:
You will now need to get your PHP script ready to translate the URLs that we will be sending to it.
I've used the following code on my site, though this is a much more simple version. You will need to use extensive error checking to make sure someone doesn't type in an invalid URL lacking key variables, and print errors if that happens.

// URL Parsing CODE
list($empty_variable,$php_script,$var1,$var2,$var3) = explode("/",$REQUEST_URI);
// END URL PARSING CODE

Third:
You will finally need to make your links point to this new file "search" rather than "search.php" and have the variables appended to the URL. An example link for the previous example would be:
/search/var1/var2/var3/

This will greatly enhance the functionality and ease of use of the site, and the link structure gives the illusion that the pages are actually static pages rather than dynamic to those search engines that don't like ?'s and &'s.

Also, this can make a visitor remembering a specific URL a little easier.

Good Luck! It's well worth the time to get this to work!!! (IMHO)

I've got at least 99% of my pages indexed by google, so it doesn't seem to hurt in any way for sure!!! :)

Alternatively, you can use Apache's mod_rewrite. I have used this so all forums and threads can be written as forum5.html and thread123.html, for example. Of course, I haven't taken the time to do this for all my pages. Perhaps I will when the new VB3 style is released :)

I'm not 100% postive offhand if you can use mod_rewrite on a shared-hosting server... Unless you have a dedicated server, or the web host for a shared server will allow .htaccess files for individual sites.

cscgal, are you using a .htaccess file for the mod_rewrite commands, or are they located directly in the httpd.conf file on the server? I know there are some limits to the uses of a .htaccess file. I'm just not sure if mod_rewrite is allowed or not... that's why I ask. :)

This PHP solution also solves the problem of having to manually set up each link or URL you want to modify to be more search friendly. Whenever new information is submitted to my database, new pages are created automatically, and applied to the search friendly URLs.

In my application, it's really only one PHP script "search" that appears to google to be more than 250,000 pages because of the link structure... and the content is unique on each of those pages depending on the variables passed in the URL.

I hope that made some sense. :D

I used mod_rewrite via a .htaccess file when I was on a shared server. I would assume that many good linux shared hosts would allow .htaccess being as it's a good way to customize 404 errors as well.

As for now being on a dedicated server, I've stuck to what I know, and am still using an .htaccess file in the /home/daniweb/www/techtalkforums/ directory. There are other threads around here showing just how I accomplished this. (I think they refer back to when these forums were using phpBB however.)

I've never had a problem with mod_rewrite on many different shared hosting servers, on Plesk, Cpanel and Dreamhost's quirky control panel. Always linux, though.

The easiest way to do this is with .htaccess. However, this is hard to get your head round at first. Once you've got it, it's easy.

I have tried doing this with php, but of course, that is much slower. .htaccess is the best choice imvho

This article has been dead for over six months. Start a new discussion instead.