Being in permanent difficult thoughts about web-technologies and his involvement in them, I decided to share one simple thought.
It was: The
KISS principle is currently used poorly, and this is bad!
UPD 1: Aftyr is trying to invent a bicycle, will we help him in this? :)
UPD 2: The author does not help ... :)
')
It was: Such a ridiculous conclusion was made on the basis of the analysis of the .htaccess settings for several ultra-popular systems.
UPD 3: The author apologizes to all fans of such settings, but is still trying to understand "what is simpler," the author does not deny that he "is still learning" ... :)
What exactly? ::
Over the past couple of months, I was forced to familiarize myself with the “boxed” mod_rewrite settings in the .htaccess files of the following systems:
- 1C-Bitrix
- Amiro
- Drupal
- Joomla
- Wordpress
- TYPO3
- Cogear
Just do not think that I do not like them, just the opposite! They are good, everything, in their own way, are good for "their" tasks! And yes, I “watched” / “used” all of them one way or another!
The principle on which the settings are arranged corresponds to the following logic:
If there is no file, then go to the engine .Namely, in general terms like this:
<IfModule mod_rewrite.c>
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ <u> index.php </ u> [L]
</ IfModule>
Why this principle is used so universally - I could not answer.
Apparently once upon a time someone decided that this would be best.
Since then, no one really thinks, because it works, why change?
Apparently, this is really convenient, but ...
What gives us the use of this principle:
- The engine analyzes the URL, looking for a record in the database.
- If there is no record, 404 is issued.
- If access to the current user is "denied" - 403.
- In general, we are unable to "display" the standard 404 server error.
- Sometimes, for those pages that "exist", we are forced to write inserts in the code for "pulling up" the engine and templating engine, etc. Although, in general, of course, you can get rid of this by adding them to the engine, if they are not there.
By the way, in AmiroMS and a number of others, I suspect that “archaic” is generally used on the basis of processing 404 errors, this is “ze best”! Although the system (do not consider it an advertisement) as a whole is not bad (well, I have to say something positive, since I have already said something negative).
And, here's the question - what to do, what to do?
For self-written (from scratch) business cards with a dozen pages, I now do this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond% {REQUEST_FILENAME} -s
RewriteCond% {REQUEST_FILENAME}! -L
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ (. *) $ ../Index.php?fn=%{REQUEST_FILENAME} [NS, NC, L]
</ IfModule>
What does this give me:
- "Static" begins to be processed only if it is.
- If there is no static, then it should be so, we give 404 "out of default."
- To statics you do not need to “tie” the template, it is in the engine itself, right away.
What is my “static”?
Text files, banal text files ...
The first line is TITLE.
The second line is HEAD INCLUDE: everything I need to insert to the end of the head.
Everything below the third line - the body of the page ...
The usual template, the usual such template, is connected to the engine after I “select” these three “variables” from the statics. I can make as many variables as I like, I can separate them with “special sequence-special characters” so that it “everything” will be.
Does it work fast?
I did not do tests, but, IMHO - not slower.
And what about the database data?
So, and who prevents to make a page for each "controller", or embed "controllers" in the body of the page and process "according to parameters".
Security?
In PHP, I am a neophyte, I built such a check into the beginning of the “engine”, but I suppose that with the correct access settings it is not needed at all.
<? php
if (isset ($ _ GET ["fn"])) {
if (stristr ($ _ SERVER ["REQUEST_URI"], $ _SERVER ["SCRIPT_NAME"]) === false) {
$ fn = $ _GET ["fn"];
if (file_exists ($ fn) === true) {
$ direct = 'y';
require_once ('core.php');
} else {
$ type = 404;
require_once ('error_report.php');
}
require_once ('core.php');
} else {
require_once ('error_report.php');
}
} else {
require_once ('error_report.php');
}
?>
I am pleased to hear comments on her fallacy.
Thanks for attention!