Using Search Engine Friendly PHP URLs

Reply

Join Date: Aug 2003
Posts: 82
Reputation: himerus is an unknown quantity at this point 
Solved Threads: 0
himerus's Avatar
himerus himerus is offline Offline
Junior Poster in Training

Using Search Engine Friendly PHP URLs

 
0
  #1
Nov 16th, 2003
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.
  1. <Directory /home/blah/domain.com/httpdocs/>
  2. <Files search>
  3. ForceType application/x-httpd-php
  4. </Files>
  5. </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.

[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!!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 207
Reputation: rixius is an unknown quantity at this point 
Solved Threads: 1
rixius rixius is offline Offline
Posting Whiz in Training

Re: Using Search Engine Friendly PHP URLs

 
0
  #2
Nov 16th, 2003
Excellent, this will come in handy.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,040
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Using Search Engine Friendly PHP URLs

 
0
  #3
Nov 16th, 2003
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
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Aug 2003
Posts: 82
Reputation: himerus is an unknown quantity at this point 
Solved Threads: 0
himerus's Avatar
himerus himerus is offline Offline
Junior Poster in Training

Re: Using Search Engine Friendly PHP URLs

 
0
  #4
Nov 16th, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,040
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Using Search Engine Friendly PHP URLs

 
0
  #5
Nov 16th, 2003
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.)
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Using Search Engine Friendly PHP URLs

 
0
  #6
Nov 23rd, 2003
Yep, you can use mod_rewrite on shared servers, because of their per-directory capabilities
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC