Htaccess - regular expressions

lair360

New Member
Messages
200
Reaction score
0
Points
0
Version: 16.1a
Revision: 33 Build 18


Htaccess - regular expressions

Introduction: many users these days aren’t sure about “htaccess” syntax and their regular expressions. So, I’ve written this article to stop you from getting confuse!


. (full stop) - match any character and any single character
* (asterix) - match zero or more of the previous symbol
———————————
Notes: * - means one or more of the preceding characters


+ (plus) - match one or more of the previous symbol
? (question) - match zero or one of the previous symbol
\? (backslash-something) - match any special characters
^ (caret symbol) - match the start of a string

# - this symbol is a commented-out line
——————————–
Notes: ^ - refers to the beginning of a string. So any syntax that has ^ in it means “starts with”


$ (dollar symbol) - match the end of a string
——————————–
Notes: $ - refers to the end of the string. So any syntax that ends with $ means “ends with” the previous character


[set] - match any of the symbols inside the square braces
(pattern) - grouping, remember what the pattern matched as a special variable


Extended information
——————————–
^$ - refers to a string that starts and stops with nothing in between, also known as an empty string, as there’s nothing in it.


^demo.* - refers to a string that starts with “demo” and then may contain any number of any characters.


^globalnews\.net$ - refers to a string that contains only “globalnews.net”


! symbol is a negation. Anywhere you see a ! (exclaimation mark), it means denied or exclude. So, “!string”, matches everything except (exclude) string.


Exclusion is a very useful method and it will allow your domain from being block by htaccess as bad referrers and agent-robots.


!^friend1@client1.mydomain\.com$


Notes: the ! symbol notify the engine to exclude “friend1@client1.mydomain” from a “.com” domain. This way, your website or friend’s site will not get block.


——————————–
Advice: ^(.*)$ - the ^ (caret) symbol defines the start, (.*) is a designated variable (using brackets) containing a regular expression that matches any combination of characters, and the $ symbol defines the end.


That is all everyone and thank you for your support!


Copyrighted by Lair360
 
Top