htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: SEO Friendly URLs for PHP
PostPosted: 02 Oct 2006 02:38 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
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.


Code:
<Directory /askapache.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.


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.

Code:
list($empty_variable,$php_script,$var1,$var2,$var3) =
explode("/",$REQUEST_URI);



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/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB