Click to See Complete Forum and Search --> : URL of php written sql content pages


LindaQ
10-07-2003, 12:13 AM
I have tried doing a search, but didn't find anything...

I write all of my websites using a PHP index page, and all of the content is stored in a MySql database.

The websites that I create have a URL of http://www.websitename.com/?s=pagename (or for a current one http://www.websitename.com/index2?s=pagename, as I am using several different index page designs).

I really want to make the URL more search engine friendly (and look a whole lot better) by being something that hides all the php stuff (even something like http://www.websitename.com/pagename would be good).

Is there a simple way to do this (I have read some instructions that were waaay too complicated and time consuming).

Thank you in advance.

fyrestrtr
10-07-2003, 12:36 AM
I would recommend using mod_rewrite (in Apache), which is perfect for this kind of problem.

Given a URL such as

http://www.domain.com/file.ext?s=text

Which you would like to convert to

http://www.domain.com/text

You can use this RewriteRule :
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite URLs of the form 'file.ext?s=x':

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ file.ext?s=$1 [L,QSA]
</IfModule>

Where file.ext can be anything you want. So if your file is index.php, simply replace.

Let me know if this works. I'm not a mod_rewrite guru ... its a dark art and I haven't sold my soul to the devil yet :P

Edit :

This rule will also work for situations such as s=foo/bar/ext ... the URL then will become www.domain.com/foo/bar/ext.

You can find out more about making search engine friendly URLs using PHP by reading this article (http://www.evolt.org/article/Search_Engine_Friendly_URLs_with_PHP_and_Apache/17/15049/index.html) on Evolt.org