{"id":2339,"date":"2021-06-29T09:59:08","date_gmt":"2021-06-29T06:59:08","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=2339"},"modified":"2022-02-08T11:01:24","modified_gmt":"2022-02-08T09:01:24","slug":"how-can-i-enable-mod_rewrite-module","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-can-i-enable-mod_rewrite-module\/","title":{"rendered":"How Can I Enable Mod_Rewrite Module?"},"content":{"rendered":"<p><b>After moving your website<\/b><span style=\"font-weight: 400;\">, you can rewrite the URLs to forward visitors to the<\/span><b> new <\/b><a href=\"https:\/\/www.scalahosting.com\/kb\/change-your-domain-name\/\"><b>domain name<\/b><\/a><span style=\"font-weight: 400;\">, saving you from traffic and potential sales losses.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can also rewrite ugly and unwieldy URLs (like www.mystore.com\/p=72829) to make them intuitive for shoppers, for example, to something like&nbsp; <\/span><b>www.mystore.com\/computers\/laptops\/hp.&nbsp;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The link is easier on the eyes, looks clean, and<\/span><b> visitors can extract semantic meanings.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Of course, enabling the mod_rewrite module makes this possible. So let\u2019s learn what it\u2019s, how it works and <\/span><b>how to enable it for your account.<\/b><\/p>\n<h2><b>What\u2019s Mod_Rewrite?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The mod_rewrite&nbsp; is an <\/span><b>Apache module<\/b><span style=\"font-weight: 400;\"> that helps users manipulate or rewrite URLs from the server, allowing them to offer different URLs for the same file.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The module uses a rule-based rewriting engine to let<\/span><b> users rewrite URLs.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Users can enable the .htaccess file after <\/span><b>activating the mod_rewriting module <\/b><span style=\"font-weight: 400;\">to let them rewrite URLs via the file on their account control panel instead of on their remote servers.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The .htaccess file <\/span><b>allows people to configure server settings <\/b><span style=\"font-weight: 400;\">without accessing its configuration files.<\/span><\/p>\n<h2><b>How the Rewrite Rule Works<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The mod_rewrite module <\/span><b>relies on rules to match URLs.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">When a visitor makes a URL request,<\/span><b> the module checks the incoming URLs <\/b><span style=\"font-weight: 400;\">against existing rules, which use regular expressions to define the match condition or pattern.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If the URL matches a rule, it<\/span><b> checks the defined condition and proceeds to the next rule<\/b><span style=\"font-weight: 400;\"> until there are no more rules left, and then executes the substitution.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For instance, if you set up a <\/span><b>rewrite rule <\/b><span style=\"font-weight: 400;\">that forwards users from www to non-www when they make a page request, the module will compare the URL against all existing rules&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If it matches the www to non-www rewrite rule and other defined rules (for instance, HTTP to HTTPS redirect),<\/span><b> it executes all the rewrites at once.<\/b><\/p>\n<p><b>The mod_write syntax follows this pattern <\/b><b>RewriteRule Pattern Substitution [Flags]:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>RewriteRule<\/b><span style=\"font-weight: 400;\"> specifies the name of the mod_rewrite directive you want to use.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Pattern<\/b><span style=\"font-weight: 400;\"> shows the regular expression that matches the requested URL.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Substitution<\/b><span style=\"font-weight: 400;\"> defines the URL of the page you wish to forward to or display.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Flags<\/b><span style=\"font-weight: 400;\"> specify additional but optional parameters.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Here\u2019s a <\/span><b>sample mod_rewrite rule syntax<\/b><span style=\"font-weight: 400;\"> for redirecting non-www URLs to www.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">RewriteEngine On<\/span><\/p>\n<p><span style=\"font-weight: 400;\">RewriteCond %{HTTP_HOST} !^www\\. [NC]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">RewriteRule ^(.*)$ http:\/\/www.%{HTTP_HOST}\/$1 [R=301,L]<\/span><\/p>\n<h2><b>Importance of Mod_Rewrite<\/b><\/h2>\n<p><b>Mod_write\u2019s flexibility makes it so powerful and exciting; let\u2019s examine some of its benefits quickly:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The module helps users to<\/span><b> rewrite ugly URLs into friendlier and clean URLs.<\/b><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">It allows users to redirect visitors from www to non-www URLs or vice versa, which helps address duplicate content issues.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You can <\/span><b>redirect web visitors<\/b><span style=\"font-weight: 400;\"> to your new domain name when you change the domain using a mod_rewrite rule.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You can block specific or <\/span><b>multiple <\/b><a href=\"https:\/\/www.scalahosting.com\/blog\/how-to-manage-ip-addresses-on-your-vps\/\"><b>IP addresses<\/b><\/a><span style=\"font-weight: 400;\"> using a rewrite rule.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Most international eCommerce uses mod_rewrite rules to forward visitors from certain countries to the right place, category or store.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You can deny users access to certain file types, like <\/span><b>.pdf, .css, and others.<\/b><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">It helps web admins force their websites to load securely using HTTPS.&nbsp;<\/span><\/li>\n<\/ul>\n<h2><b>Enabling Mod_Rewrite Module<\/b><\/h2>\n<p><b>Scala Hosting installs and enables mod-rewrite modules<\/b><span style=\"font-weight: 400;\"> on Apache web servers by default. If the module is not enabled for you, contact our support, and we\u2019ll get it done.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">But if you wish to enable it yourself, then head to your server and find the global configuration file,<\/span><b> httpd.conf<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Locate the section that loads a bunch of modules and<\/span><b> find the line below within the file.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">LoadModule rewrite_module modules\/mod\\_rewrite.so<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Uncomment the line if it\u2019s commented out by removing the hashtag (#) at the beginning of the line. Please <\/span><b>ensure to make a <\/b><a href=\"https:\/\/www.scalahosting.com\/kb\/restore-data-backups\/\"><b>backup of your file<\/b><\/a> <span style=\"font-weight: 400;\">before modifying the global configuration file.<\/span><\/p>\n<h2><b>Need Support?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Scala Hosting installs and enables Apache mod_rewrite on your server by default, so you don\u2019t have to worry about <\/span><b>modifying your server global configuration file.&nbsp;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">But if you have questions <\/span><b>relating to mod_rewrite,<\/b><span style=\"font-weight: 400;\"> you can reach out to<\/span> <a href=\"https:\/\/www.scalahosting.com\/kb\/\"><b>our support<\/b><\/a><b>,<\/b><span style=\"font-weight: 400;\"> and we\u2019ll be glad to answer them.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After moving your website, you can rewrite the URLs to forward visitors to the new domain name, saving you from traffic and potential sales losses.&nbsp; You can also rewrite ugly and unwieldy URLs (like www.mystore.com\/p=72829) to make them intuitive for shoppers, for example, to something like&nbsp; www.mystore.com\/computers\/laptops\/hp.&nbsp; The link is easier on the eyes, looks [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_seopress_analysis_target_kw":"","footnotes":""},"categories":[22],"tags":[],"class_list":["post-2339","post","type-post","status-publish","format-standard","hentry","category-dns"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=2339"}],"version-history":[{"count":3,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2339\/revisions"}],"predecessor-version":[{"id":3226,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/2339\/revisions\/3226"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=2339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=2339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=2339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}