.htaccess - Why use RewriteCond and RewriteRule to test a url condition? -
To rewrite the rules of several rules, when url is tested for a certain condition, then I A mix of Rewight Condoles is used with REQUEST_URI, and rewrite rule.
Is this just a personal preference, or is there any performance reason, or clarity of rules? These are all valid reasons, in my opinion; I'm just wondering if there is any special reason.
I know that there are situations where revrovined is the only option. I am interested in the cases where rearctarial will also work. Generally these are simple rules.
Here are some examples:
Example 1
This answer has a similar pattern, like some folders-
# always these folders allow RewriteCond% {REQUEST_URI} ^ / display_me_always [or] RewriteCond% {REQUEST_URI} ^ / another_folder [or] RewriteCond% {REQUEST_URI} ^ / even_more_folders RewriteRule + -. [L] It can only be done with a rewrite as follows:
RewriteRule ^ / (?: Display_me_always | another_folder | Even_more_folders) - [L] (For non-capturing? Has been added. I'm never sure if there's an easy rule or not, to capture.)
EXAMPLE 2
Modifying it for a more general scenario, redirecting some folders to other folders.
RewriteCond% {REQUEST_URI} ^ / display_me_always [or] RewriteCond% {REQUEST_URI} ^ / another_folder [or] RewriteCond% {REQUEST_URI} ^ / even_more_folders RewriteRule ^ / [^ /] + / ( . *) $ / other_location / $ 1 [L] this rule only
RewriteRule ^ / (?: look simple with display_me_always |. another_folder | EXAMPLE 3
There is a general pattern present in this reply, if not already, then redirect the target location. Test the folder with the rewrite link. , Then check the file with the rule.
Doing me with Revittend A negative situation for the area appears very clear, but it is still possible with RewriteRule.
RewriteCond% {REQUEST_URI}! ^ / Web_content / PDF / RewriteRule ^ (. + \ .pdf) $ / web_content / pdf / $ 1 [L] This can be written as
Rewrite rule ^ (? / Web_content / Pdf /) (. + \ .pdf) $ / web_content / pdf / $ 1 [L]
A simple reason: This is very easy for a non reggae master. The rewrite rule is that today you will give it to OP, it may need to be modified one day later .. And the more likely the rule is understood, the more he will see himself and at this place again Another small fine / new uniform rule from
Yes, the joint rule is fast - there is no doubt here. But the time spent in retyping the URL is still very small compared to a single script execution ... it can make a difference only on a very CPU busy server and when there are so many such rewrites.
Therefore, the most optimal will be something in between - which is still easy to read and compact and efficient at the same time. Instead # always these folders RewriteCond% {REQUEST_URI} ^ / display_me_always [or] RewriteCond% {REQUEST_URI} ^ / another_folder [or] RewriteCond% {REQUEST_URI} ^ / even_more_folders give RewriteRule allowed . + - [L] Offer
# Always allow these folders RewriteCond% are {REQUEST_URI} ^ / (display_me_always | another_folder | even_more_folders). RewriteRule + - [L] You can not become a master in a day or two (unless you're probably not a genius) - Everything takes time. And the more practical experience is better for you to move forward (by modifying these rules yourself) to build a more efficient / stable regime. BTW: This rule will not work if kept in .htaccess (the URL matches the pattern starts with a leading slash): RewriteRule ^ / (?: Display_me_always | another_folder | even_more_folders) - [l] but will work fine if the server config / kept in the virtual host context - That's one of the "nuances" you want to know
Comments
Post a Comment