You are here: Re: Search engine friendly URLs « PHP Programming Language « IT news, forums, messages
Re: Search engine friendly URLs

Posted by BRADINO on 11/24/06 22:31

Hey Geoff,

One if the cleanest ways to setup a site is to use mod_rewrite in
Apache. I am going to show you a simple way to do this using an
htaccess file and a little PHP. First step is to make an htaccess file
with the following code:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?loc=$1

Now everything that is not a folder or a file will get passed to the
index.php file as $_GET['loc']. You could change the index.php to any
file you like and the ?loc= to some other variable if you like.

Next you need to groom the url. Do not leave out this step. You are
injecting the url into your script... I suggest something solid like
the following:

<?php
$url = preg_replace('/[^[:alnum:]\-\/]/', '', $_GET['loc']);
?>

So now you have the url into your script safely so you need to break it
apart. You are basically going to pass variables here. All you have to
do is explode on the forward slash. You can do it simply like this:

<?php
$parts = explode('/',$url);
$section = $parts[0];
$subsection = $parts[1];
?>


Hope this helps!

http://www.bradino.com/apache/mod-rewrite/

BRAD

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация