Home
Home Page
XML on the screen of a browser
Interaction with life cycle of page
How to overtake competitors and at once to do{make} liderskie pages
Adjustment of parameters PHP in php.ini
KHehshirovanie passwords in PHP
Total Automation of Reception of payments on a site
Object-oriented programming, classes in PHP
Abstract classes and interfaces
The module of definition of a geographical position on IP - mod_GeoIP
Conclusion of messages to the user in webs - applications.
Manipulation date on PHP
The truth about Sessions
Realization of patterns on PHP.
Protection against a spam on a site
Imitation of files and directories
Door in protection: the post web - interface
Safety of search engines in the corporate environment
CHPU and PHP (revisited)
Links
 
 

CHPU and PHP (revisited)

CHPU is the term which has been thought up by NovoKiberska command, he designates « CHelovekoponjatnyj URL ». The term anywhere widely was not used, while I have not written on September, 5, 2000 a note « CHPU and PHP ». For these three years the term was rather not bad untwisted.


For these years very much many referred to this note, therefore I have taken the trouble to copy her , having added some more ways to make CHPU and having cleaned{removed} any dust. So …


Basically, anything new and original in idea understandable URLa no. About it wrote and Lebedev, and other comrades. In general, to me always liked URLy such, for example, a kind: http://php.resourceindex.com/Complete_Scripts/Guestbooks/


So, how it to make in domestic conditions?


Way of times


In general, the very first idea is to create for each note a subdirectory with a corresponding name and to place in it{her} index.html, that is to make so that to the address http://spectator.ru/technology/php/user_friendly_urls the real file would lay. Certainly, so business will not go.


Way two


We think further. Time page does not exist, she gives out 404. So the second idea - to register in fale .htaccess page which will be given out at a mistake 404, and this page will already look on current URL and to give out the necessary document


That is, in .htaccess we write:



------------------------------------

ErrorDocument 404/index.php3

ErrorDocument 401/index.php3

------------------------------------


The user types{collects} http://spectator.ru/technology/php/user_friendly_urls, such page is not found, and the file index.php3 is loaded. Further - all is simple. The variable $REQUEST_URI gives us the address of caused page (in this case it will be/technology/php/user_friendly_urls), to display the corresponding document - a trick.


It is not enough of it. In some browsers and with poiskovikami such focus will not pass: page 404 will give out a corresponding code, and pages will not be indexed. Therefore it is necessary, that the page which gruzitsja in case of a mistake 404, would change an error code and signalled supposedly all OK, there is such page: <? php header (" http/1.0 200 Ok ");?>


Total: we register in .htaccess page which, actually, for all responds (at me it index.php3). In this page we write a php-script which works with $REQUEST_URI, sends heading « http/1.0 200 Ok » and displays that is necessary.


Pluss: very simple way. Works almost everywhere.

Minuses: At such way it is impossible postit` contents of the form on nonexistent psevdourly. And if in the Apache the broad gully of 404-s' mistakes he will be hammered is conducted.


Way three


For these (and not only) the purposes there is a special module in the Apache who is called mod_rewrite. He allows « perepisyvyvat` urly », that is, to transform them "hurriedly" by rules which you to him describe.


It is very powerful module and if you will understand him can work wonders. I till now very little with it  worked, therefore read the documentation, the blessing, that of her  it is full.


Module mod_rewrite URL Rewriting Engine.

A Users Guide to URL Rewriting with the Apache Webserver.

Module Apache mod_rewrite.

Mod_rewrite For teapots.


Pluss: very powerful way.

Minuses: brains Can not suffice. On a hosting this module can be not established.


Way four


It is based on FilesMatch directive which in the Apache is core feature. All is simple. We write besides in .htaccess



Action throw/index.php


<FilesMatch " ^ ([^]. +) $ ">

ForceType throw

</FilesMatch>


<FilesMatch index.php>

ForceType application/x-httpd-php

</FilesMatch>


After that all URLy which fall under a condition « ^ ([^.] +) $ », (that is all urly which do not contain a point) will be passed on index.php. You can write the condition, certainly.


Pluss: the Simple and convenient way.

Minuses: Speak, that that ForceType worked, php should be connected to the apache as the module. If php it is caused, as ordinary CGI - ForceType will not work.