E
E
Evgeny Khakhalkin2016-03-23 07:33:31
Apache HTTP Server
Evgeny Khakhalkin, 2016-03-23 07:33:31

How would I deal with htaccess?

Good day to all.
Now I am studying a series of lessons on creating a site engine in php (more precisely, I have already studied it). The essence of the engine is as follows: there is an index.php file and, in fact, all other *.php work through it. htaccess was not explained in the tutorials. It was just said to add this file with this code to the root of the folder with the site and that's it:

  1. Rewrite Engine on
  2. RewriteBase /
  3. Options All-Indexes
  4. RewriteCond %{REQUEST_FILENAME} -s [OR]
  5. RewriteCond %{REQUEST_FILENAME} -l [OR]
  6. RewriteCond %{REQUEST_FILENAME} -d
  7. RewriteRule ^resource/(.*)$ resource/$1 [L]
  8. RewriteRule ^catalog/(.*)$ catalog/$1 [L]
  9. RewriteRule ^.*$ [NC,L]
  10. RewriteRule ^.*$ index.php [NC,L]
  11. AddDefaultCharset UTF-8
  12. AddType 'text/html; charset=utf-8' .html .htm .shtml

But this code did not give me rest and therefore I decided to deal with it. I read the documentation and articles. And partially understood. And so, in order, as I understand this code:
1. The first line, as I understand it: launches some kind of mod that will convert the URL.
2. The second line specifies the directory where the conversions will take place.
3. If there is no index.php then the directory on the server will not be displayed.
4-6. Conditions under which rule 7 will work. (Ie, if the full path to the file or the file itself: a) is a regular file with a non-zero size; b) is a symbolic link; c) is a directory).
Attention, question: When will rule 7 be triggered: if all three conditions are met, or at least one. This question arose because:
Use OR instead of AND to combine conditions in rules.

7. We replace resource/{any symbols} with resource/$1 and [L] - we finish transformations and do not transform anything else.
Attention, question: What does $1
8 mean. The same as the previous rule, only the parameters are different, but..
Attention, the question: Why are there no conditions here. Well, again $1.
9. Immediately ..
Attention, the question is: What is going on here? Those. we convert absolutely any URL to.... Nothing?! There is no second parameter.
10. Here, it seems to me, the rule means redirecting any request to index.php.
Attention, question: Right?
11-12. Everything is clear here.
Attention, the main question: Why does only one rule have a condition, and why does it work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
trevoga_su, 2016-03-23
@djonslaterye

I advise you to abandon this approach when you write conditions for the site in the htaccess server configuration file.
This is already an outdated practice, and even from an ideological point of view, it is not correct when the function of routing a web application is assigned to the server configuration file.
Read - www.phpinfo.su/articles/practice/chpu_na_php.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question