| | |
Using Search Engine Friendly PHP URLs
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
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.
[php]
// URL Parsing CODE
list($empty_variable,$php_script,$var1,$var2,$var3) = explode("/",$REQUEST_URI);
// END URL PARSING CODE
[/php]
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!!!
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.
PHP Syntax (Toggle Plain Text)
<Directory /home/blah/domain.com/httpdocs/> <Files search> ForceType application/x-httpd-php </Files> </Directory>
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.
[php]
// URL Parsing CODE
list($empty_variable,$php_script,$var1,$var2,$var3) = explode("/",$REQUEST_URI);
// END URL PARSING CODE
[/php]
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!!!
•
•
Join Date: Nov 2003
Posts: 207
Reputation:
Solved Threads: 1
Excellent, this will come in handy.
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.
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.
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.)
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.)
![]() |
Similar Threads
- Search Engine Friendly URLs Help in SEO (Search Engine Optimization)
- Search Engine Friendly, No reciprocal link free Webmaster Directory! (Relevant Link Exchanges)
- How to convert url to search engine friendly (PHP)
- Search Engine Friendly Design (Search Engine Optimization)
- Search Engine friendly vBulletin URL (Search Engine Optimization)
- Search Engine Friendly URL:s in IIS-solutions? (Search Engine Optimization)
Other Threads in the PHP Forum
- Previous Thread: PHP Programmer interested in an existing project? Game! =o]
- Next Thread: Need a tutorial on sessions
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file files filter folder form forms forum function functions gc_maxlifetime global google headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql query question random recourse recursion regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube






