htaccess Syntax | Definition |
---|---|
# | the # instructs the Web Server to ignore the line. used for including comments. each line of comments requires it’s own #. when including comments, it is good practice to use only letters, numbers, dashes, and underscores. this practice will help eliminate/avoid potential Web server parsing errors. |
[F] | Forbidden: instructs the Web Server to return a 403 Forbidden to the client. |
[L] | Last rule: instructs the Web Server to stop rewriting after the preceding directive is processed. |
[N] | Next: instructs Apache to rerun the rewrite rule until all rewriting directives have been achieved. |
[G] | Gone: instructs the Web Server to deliver Gone (no longer exists) status message. |
[P] | Proxy: instructs Web Server to handle requests by mod_proxy |
[C] | Chain: instructs Web Server to chain the current rule with the previous rule. |
[R] | Redirect: instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL. |
[NC] | No Case: defines any associated argument as case-insensitive. i.e., "NC" = "No Case". |
[PT] | Pass Through: instructs mod_rewrite to pass the rewritten URL back to Apache for further processing. |
[OR] | Or: specifies a logical "or" that ties two expressions together such that either one proving true will cause the associated rule to be applied. |
[NE] | No Escape: instructs the Web Server to parse output without escaping characters. |
[NS] | No Subrequest: instructs the Web Server to skip the directive if internal sub-request. |
[QSA] | Append Query String: directs Web Server to add the query string to the end of the expression (URL). |
[S=x] | Skip: instructs the Web Server to skip the next "x" number of rules if a match is detected. |
[E=variable:value] | Environmental Variable: instructs the Web Server to set the environmental variable "variable" to "value". |
[T=MIME-type] | Mime Type: declares the mime type of the target resource. |
[] | specifies a character class, in which any character within the brackets will be a match. e.g., [xyz] will match either an x, y, or z. |
[]+ | character class in which any combination of items within the brackets will be a match. e.g., [xyz]+ will match any number of x’s, y’s, z’s, or any combination of these characters. |
[^] | specifies not within a character class. e.g., [^xyz] will match any character that is neither x, y, nor z. |
[a-z] | a dash (-) between two characters within a character class ([]) denotes the range of characters between them. e.g., [a-zA-Z] matches all lowercase and uppercase letters from a to z. |
a{n} | specifies an exact number, n, of the preceding character. e.g., x{3} matches exactly threex’s. |
a{n,} | specifies n or more of the preceding character. e.g., x{3,} matches three or more x’s. |
a{n,m} | specifies a range of numbers, between n and m, of the preceding character. e.g., x{3,7} matches three, four, five, six, or seven x’s. |
() | used to group characters together, thereby considering them as a single unit. e.g., (perishable)?press will match press, with or without the perishable prefix. |
^ | denotes the beginning of a regex (regex = regular expression) test string. i.e., begin argument with the proceeding character. |
$ | denotes the end of a regex (regex = regular expression) test string. i.e., end argument with the previous character. |
? | declares as optional the preceding character. e.g., monzas? will match monza or monzas, while mon(za)? will match either mon or monza. i.e., x? matches zero or one of x. |
! | declares negation. e.g., “!string” matches everything except “string”. |
. | a dot (or period) indicates any single arbitrary character. |
- | instructs “not to” rewrite the URL, as in “...domain.com.* - [F]”. |
+ | matches one or more of the preceding character. e.g., G+ matches one or more G’s, while "+" will match one or more characters of any kind. |
* | matches zero or more of the preceding character. e.g., use “.*” as a wildcard. |
| | declares a logical “or” operator. for example, (x|y) matches x or y. |
\ | escapes special characters ( ^ $ ! . * | ). e.g., use “\.” to indicate/escape a literal dot. |
\. | indicates a literal dot (escaped). |
/* | zero or more slashes. |
.* | zero or more arbitrary characters. |
^$ | defines an empty string. |
^.*$ | the standard pattern for matching everything. |
[^/.] | defines one character that is neither a slash nor a dot. |
[^/.]+ | defines any number of characters which contains neither slash nor dot. |
http:// | this is a literal statement — in this case, the literal character string, “http://”. |
^domain.* | defines a string that begins with the term “domain”, which then may be proceeded by any number of any characters. |
^domain\.com$ | defines the exact string “domain.com”. |
-d | tests if string is an existing directory |
-f | tests if string is an existing file |
-s | tests if file in test string has a non-zero value |
For example :
Added file notfound.html in the root directory of webeite site and use it for a 404 error Define in htaccess bellow code: ErrorDocument 404 /notfound.html
These are some of the most common errors browser:
- 401 - Authorization Required
- 400 - Bad request
- 403 - Forbidden
- 500 - Internal Web Server Error
- 404 - Wrong page
No comments:
Post a Comment