Transformation of hyperlinks by means of Apache server
Wandering open spaces of the Internet you saw set of various hyperlinks, the some people had a different kind, passing various signs (?, and;), etc.
If the link still pleasant kind is a little signs has, but some links are not so clear. For example the link has such kind. http: // www.webobzor.net/index.php? mod=stat
There is nothing complex{difficult}, but the address can look and so http://www.webobzor.net/stat So it is better? So it is possible to pass not one parameter.
Probably you met similar links to some sites, likely you have thought that the script for each file creates a separate folder. Yes, it is a variant, but wrong. Completely not necessarily so to act.
And as it to make, not creating separate catalogues, the answer is absolutely simple, developers of our liked Apache server have thought up the module mod_rewrite which and will help us with this question.
The module mod_rewrite
mod_rewrite Is a special module for Apache servers which has been specially made for creation of sites with CHPU. He has been written in April, 1996 and exclusively presented The Apache Group in July 1997.
The module represents library of expansion for servers such as Apache. Is in a folder modules, in a root folder of the apache and is called usually mod_rewrite.so (it is established separately). With the help mod_rewrite it is possible all in pair lines in .htaccess to make understandable for the person url.
Connection of the module mod_rewrite
Go in the catalogue in which you is established Web - Apache server, open a folder modules, and be convinced that at her there is a file mod_rewrite.so.
The file at us is now pass to the catalogue conf and open a file httpd.conf, it is necessary for you to be convinced that the given module is connected, for this purpose find such line
LoadModule rewrite_module modules/mod_rewrite.so
Have found? No then add this line.
Save changes in a file httpd.conf and reload the server.
Let's transform a hyperlink
In the catalogue where at you are carried out PHP scripts, create a file .htaccess. Write down in a file .htaccess such lines:
RewriteEngine On
RewriteBase/test
RewriteRule index.php.* - [L]
RewriteRule ^ (. *) index.php? id = $ 1
In line RewriteEngine On - we inform the server that we want to use means of module Rewrite.
Line RewriteBase/test - Specifies to the server where to search for a file index.php (or what at you by default) if you this line specify a wrong way the server will load a file from the specified folder, instead of cost{stand} that is necessary for you.
RewriteRule ^ (. *) index.php? id = $ 1 - this line we specify a name of a file and that it is necessary to transform.
Now we create a file index.php and we write there only one line.
<? php include ($id. ".php ")?>
I think with it all understandably, the hyperlink, for opening a file should have such kind http://localhost/test/page. Naturally, the file page.php should be already created, and be in the catalogue test.
Here is how and everything, but not here that was, a browser in any does not want to show us such file necessary for us 1.php, instead of it we see page with a mistake 404.
In what put? For that that the browser would understand that has sent him the server it is necessary in a file index.php in the top to add such recording.
<? php header (" http/1.0 200 Ok ")?>
This line speaks a browser: all OK, the page is successfully loaded. The full information by mistakes and answers of the server, read this clause{article} Codes of answers HTTP of the server
Be close{attentive}, it is necessary for you a line header (" http/1.0 200 Ok ") to place before sending of headings, i.e. in the top, differently there will be a mistake.
Unique lack of this method is that that, on your site module Rewrite and then you will see page with a mistake 500 can not be used.

|