mod_rewrite...what is it? As wiki says -
A rewrite engine is a piece of web server software used to modify URLs, for a variety of purposes.
i.e. some kind of module for a web server, enabling to modify links...In general, the rewrite engine itself exists both for apache and microsoft's IIS and even for java platforms =) In this particular article we're going to talk exactly about mod_rewrite for apache.
Everything we're gonna need is
.htaccess file radically, if you already have it..then it's only need to finish writing some certain lines in it..and surely in case hoster hasn't installed this module yet, he should be kicked around a little..)
As for me personally I use full links in .htaccess, if you want to use relative links like
/index.php?blabla=31337 then it's advisable to include the following lines in the file, which ,even though only a little bit, but speeds up the work
DocumentRoot /home/htdocs/www
<Directory /> Options FollowSymLinks
</Directory>
that is, in case you have a www site but the option isn't on then apache will be trying to find
Index.php file first in
/home/ then in
/home/htdocs/ and in the end will stumble on
/home/htdocs/www/index.php. This is nothing of course, but you'll still spare some hundredth parts of the second..) or you can write in every file before "rewrital on" the following phrase
PHP CODE:
Generally it is possible to find many ways to use in it..most popular of which - is the transformation of the link into some more readable look ) ..well, find me a man who would like the link such as
http://site.com/index.php?action=forum&forum=theme01
Let us transform it into..for instance
http://site.com/forum/someshit.htm
For this we will need to turn RewriteEngine itself on for starters:
PHP CODE:
then we overwrite the url itself:
PHP CODE:
RewriteRule ^ ([a-z]+)/([a-z0-9]+).htm$ index.php?action=$1;forum=$2
Let's clarify things related to this quite simple construction...
RewriteRule simply sets the beginning of the overwrite line.
([a-z]+) indicates that everything before "slash" is replaced with
small roman letters from a to z (everything is written into the $1 variable)
then after "slash" we see
([a-z0-9]+).htm
, that is, here we replace everything after "slash" with
small roman letters from a to z and digits from 0 to 9 ($2 variable)
, and then add
htm extension in the end of the url.
As you understand, such .htm files never actually were and will never be on your site, it's just that thus links are shown in a more comfortable way.
The most important here is to remember this order - how it goes after RewriteRule - firstly -
how to transform and only then
what to transform
As you understand that's in order to make forum fully overwrite links (urls) with parameters in htm look (not obligatory htm, it can be any kind of extension your imagination might create) for all existing transferrable by GET parameters...should it be a search, threads, forums, personal messages after all...the main thing is also not to overdo it = )
Original copyright: blackybr
English version translation: Дрэгги