{"id":4358,"date":"2021-01-14T21:59:43","date_gmt":"2021-01-14T21:59:43","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=ht_kb&#038;p=4358"},"modified":"2022-04-05T08:11:41","modified_gmt":"2022-04-05T08:11:41","slug":"htaccess-regex-characters","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/htaccess-regex-characters\/","title":{"rendered":".htaccess 101 &#8211; RegEx Characters"},"content":{"rendered":"<p>This tutorial will teach you how to use specific RegEx characters specific to .htaccess files.<\/p>\n<h2 id=\"what-is-regex\">What is Regex?<\/h2>\n<p>Before going further, RegEx is short for a regular expression &#8211; it is defined as a specific string of text used to describe a search pattern. It helps to match, locate, and manage text.<\/p>\n<h2 id=\"htaccess-regex-characters-explained\">.htaccess RegEx Characters Explained<\/h2>\n<p>The following table showcases different regex characters that are specific to .htaccess files.<\/p>\n\n<table id=\"tablepress-18\" class=\"tablepress tablepress-id-18\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Character<\/th><th class=\"column-2\">What does it do?<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">#<\/td><td class=\"column-2\">Forces the server to ignore the text following the # on the same line. Typically used for comments<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">[F]<\/td><td class=\"column-2\">Indicates Forbidden, with this the server should return a 403 forbidden error to the client<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">[L]<\/td><td class=\"column-2\">The Last rule forces the server to stop processing rules in the .htaccess file<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">[N]<\/td><td class=\"column-2\">Indicates Next and forces Apache to redo the rewrite process, except using the currently rewritten URL instead of the initial URL<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">[G]<\/td><td class=\"column-2\">Gone tells the server to deliever the gone status message, which is used to mark pages that no longer exist on the site.<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">[R]<\/td><td class=\"column-2\">This forces Apache to initialize a redirect, this can be a permanent redirect (page has moved, 301), or a temporary redirect (302).<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">[P]<\/td><td class=\"column-2\">Indicates Proxy which tells the server to use mod_proxy to handle requests<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">[C]<\/td><td class=\"column-2\">Tells the server to chain a rule with the next rule. If the rule matches for example, then the chained rules will run as well, if not, then they will not run.<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">[QSA]<\/td><td class=\"column-2\">Tells the server to use the query string at the end of an expression<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">[NC]<\/td><td class=\"column-2\">No Case instructs the server to treat any argument as case insensitive<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">[NS]<\/td><td class=\"column-2\">The No Subrequest forces the server to skip if it is an internal sub request<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">[PT]<\/td><td class=\"column-2\">Pass Through has mod_rewrite send a formatted URL back to Apache<\/td>\n<\/tr>\n<tr class=\"row-14\">\n\t<td class=\"column-1\">[NE]<\/td><td class=\"column-2\">No Escape forces the server to parse through all output ignoring escaping characters, meaning spaces in the URL will not be replaced with %20 for example<\/td>\n<\/tr>\n<tr class=\"row-15\">\n\t<td class=\"column-1\">[OR]<\/td><td class=\"column-2\">Specifies a logical \u2018OR\u2018 statement that evaluates two expressions<\/td>\n<\/tr>\n<tr class=\"row-16\">\n\t<td class=\"column-1\">[S=x]<\/td><td class=\"column-2\">Forces the server to skip \u201cx\u201d number of rules based on if a match is found, not the same as the Chain flag [C]<\/td>\n<\/tr>\n<tr class=\"row-17\">\n\t<td class=\"column-1\">[a-z]<\/td><td class=\"column-2\">Denotes a range of characters between the two characters separated by a dash<\/td>\n<\/tr>\n<tr class=\"row-18\">\n\t<td class=\"column-1\">[^]<\/td><td class=\"column-2\">Defines not within a character class, or the Start of a string of characters<\/td>\n<\/tr>\n<tr class=\"row-19\">\n\t<td class=\"column-1\">[]+<\/td><td class=\"column-2\">Defines that any combination characters defined within the brackets is a match there can be multiple matches<\/td>\n<\/tr>\n<tr class=\"row-20\">\n\t<td class=\"column-1\">[]<\/td><td class=\"column-2\">Defines that any characters defined within the brackets is a match<\/td>\n<\/tr>\n<tr class=\"row-21\">\n\t<td class=\"column-1\">[T=MIME-type]<\/td><td class=\"column-2\">Defines the mime type, forces the target file to be that mime type<\/td>\n<\/tr>\n<tr class=\"row-22\">\n\t<td class=\"column-1\">[E=variableName:newValue]<\/td><td class=\"column-2\">Forces the server to set the environmental variable \u201cvariableName\u201d to the value \u201cnewValue\u201d<\/td>\n<\/tr>\n<tr class=\"row-23\">\n\t<td class=\"column-1\">a{n}<\/td><td class=\"column-2\">Defines the specific number of the preceding character to be matched<\/td>\n<\/tr>\n<tr class=\"row-24\">\n\t<td class=\"column-1\">?<\/td><td class=\"column-2\">Defines the preceding character as being optional<\/td>\n<\/tr>\n<tr class=\"row-25\">\n\t<td class=\"column-1\">$<\/td><td class=\"column-2\">Signals the end of a regular expression<\/td>\n<\/tr>\n<tr class=\"row-26\">\n\t<td class=\"column-1\">()<\/td><td class=\"column-2\">Can be used to group characters together<\/td>\n<\/tr>\n<tr class=\"row-27\">\n\t<td class=\"column-1\">^<\/td><td class=\"column-2\">Signals the beginning of a regular expression<\/td>\n<\/tr>\n<tr class=\"row-28\">\n\t<td class=\"column-1\">.<\/td><td class=\"column-2\">Specifies a single arbitrary character<\/td>\n<\/tr>\n<tr class=\"row-29\">\n\t<td class=\"column-1\">\u2013<\/td><td class=\"column-2\">Signals not to perform an action<\/td>\n<\/tr>\n<tr class=\"row-30\">\n\t<td class=\"column-1\">!<\/td><td class=\"column-2\">Defines negation<\/td>\n<\/tr>\n<tr class=\"row-31\">\n\t<td class=\"column-1\">+<\/td><td class=\"column-2\">Will match at least one preceding character<\/td>\n<\/tr>\n<tr class=\"row-32\">\n\t<td class=\"column-1\">|<\/td><td class=\"column-2\">Logical \u2018OR\u2018 operator<\/td>\n<\/tr>\n<tr class=\"row-33\">\n\t<td class=\"column-1\">*<\/td><td class=\"column-2\">Wildcard that will match any occurrence of the preceding character<\/td>\n<\/tr>\n<tr class=\"row-34\">\n\t<td class=\"column-1\">.<\/td><td class=\"column-2\">Signals an escaped literal period<\/td>\n<\/tr>\n<tr class=\"row-35\">\n\t<td class=\"column-1\">-d<\/td><td class=\"column-2\">Analyzes if a string exists within a directory<\/td>\n<\/tr>\n<tr class=\"row-36\">\n\t<td class=\"column-1\">-f<\/td><td class=\"column-2\">Determines if a string is a preexisting file<\/td>\n<\/tr>\n<tr class=\"row-37\">\n\t<td class=\"column-1\">-s<\/td><td class=\"column-2\">Tests for a non zero value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n<p class=\"p1\"><b>Tired of experiencing issues with your site? Get the best and fastest hosting support with ChemiCloud!\u00a0<\/b><span class=\"s1\">\ud83e\udd13<\/span><b> Check out our <\/b><span style=\"text-decoration: underline;\"><a href=\"https:\/\/chemicloud.com\/pricing#60b65e4e63b58\" target=\"_blank\" rel=\"noopener\"><span class=\"s2\"><b>web hosting <\/b><\/span><\/a><\/span><b>plans!<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will teach you how to use specific RegEx characters specific to .htaccess files. What is Regex? Before going further, RegEx is short for a regular expression &#8211; it is defined as a specific string of text used to describe a search pattern. It helps to match, locate, and&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[190],"ht-kb-tag":[],"class_list":["post-4358","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-domains"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/4358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=4358"}],"version-history":[{"count":4,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/4358\/revisions"}],"predecessor-version":[{"id":7308,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/4358\/revisions\/7308"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=4358"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=4358"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=4358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}