{"id":7343,"date":"2019-06-07T10:59:52","date_gmt":"2019-06-07T10:59:52","guid":{"rendered":"https:\/\/www.milesweb.in\/hosting-faqs\/?p=7343"},"modified":"2019-06-13T11:55:39","modified_gmt":"2019-06-13T11:55:39","slug":"setup-mod-rewrite","status":"publish","type":"post","link":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/","title":{"rendered":"Learn to Set Up mod-rewrite in Simple Steps"},"content":{"rendered":"<p>Apache\u2019s mod_rewrite offers an effective and easy way for manipulating URLs. URLs are manipulated from the server side. In simple terms, mod_rewrite helps clean and user-friendly URLs to convert into websites. As per the name, it performs rewriting on URL. It can be a great way for cleaning up your website\u2019s URLs. In this tutorial, you will learn about mod_rewrite, its usage and steps to set it up on a VPS running Apache!<\/p>\n<h3>The Working of Apache mod_rewrite<\/h3>\n<p>When a URL is entered, it is checked against a list of pre-defined rules. The rules are designed to check for particular patterns or keywords. If a particular keyword is present in the URL and the rule matches, it gets replaced with a pre-defined string \u2013 a new URL.<\/p>\n<h3>What Makes mod_rewrite Useful?<\/h3>\n<p>mod_rewrite allows users to manipulate URLs into clean URLs which is the biggest advantage of it. This is easily understandable by the end user who doesn\u2019t have technical knowledge.<\/p>\n<p>You will find that these URLs are very user as well as search friendly. These URLs can be quickly identified by the search engines. What is a clean URL? Let\u2019s check the below example:<\/p>\n<p>1. URL1: http:\/\/modrewriteexample.com\/client.php?id=A786#234QA<br \/>\n2. URL2: http:\/\/modrewriteexample.com\/client\/=A786#234QA\/<br \/>\n3. URL3: http:\/\/modrewriteexample.com\/client\/Martha\/<\/p>\n<p>From the three URLs listed above, you can see that the third one is much more readable and understandable to the end user as compared to the first and second. So, URL 3 is a clean URL here.<\/p>\n<h3>Steps to Set Up mod_rewrite on a Linux VPS<\/h3>\n<p>Prior to starting, you will need to access your VPS using SSH. Now let\u2019s start the process:<\/p>\n<h3>1. Install Apache<\/h3>\n<p>In this example, we are using Ubuntu 18.04. It comprises of a built-in package installer \u2013 apt-get. First, you will need to update it by running the below command:<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get update<\/pre>\n<p>Now you can proceed with apache2 installation:<\/p>\n<p>Use the below command for installation:<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get install apache2<\/pre>\n<h3>2. Enable mod_rewrite<\/h3>\n<p>Now, you have to enable mod_rewrite with the below command:<\/p>\n<pre class=\"lang:default decode:true \">sudo a2enmod rewrite<\/pre>\n<p>This will enable the rewrite mode or will let you know if it is already in use. Then restart Apache using this command:<\/p>\n<pre class=\"lang:default decode:true \">sudo service apache2 restart<\/pre>\n<h3>3. Create the .htaccess File<\/h3>\n<p>It is important for the URL rewrite rules to be pre-defined. This is where .htaccess comes into the picture. All the rules in the .htaccess file can be written by the user. As this file is used by the server, there should not be any errors on this file or else it will return a server error. Rewrite riles can be modified at any point in time.<\/p>\n<p>It is important to create the .htacess file at the root to test the rewrite functionality.<\/p>\n<p>First run the below command:<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/var\/www\/html\/.htaccess<\/pre>\n<p>With this command, the .htaccess file will be created if it is not yet present, or opened it if it exists. Now, just save and exit it. In nano, you just have to press <strong>CTRL+O<\/strong> to save, and<strong> CTRL+X<\/strong> to exit.<\/p>\n<p>Next open the <strong>000-default.conf<\/strong> file located in the <strong>\/etc\/apache2\/sites-enabled\/directory<\/strong>. This can be done with the below command:<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/etc\/apache2\/sites-enabled\/000-default.conf<\/pre>\n<p>Inside this file, type the below block after the string :<\/p>\n<pre class=\"lang:default decode:true\">&lt;Directory \/var\/www\/html&gt;\r\nOptions Indexes FollowSymLinks MultiViews\r\nAllowOverride All\r\nOrder allow, deny\r\nallow from all\r\n&lt;\/Directory&gt;<\/pre>\n<p>Save the file similar to the .htaccess. For the changes to take effect, restart Apache as mentioned in step two above.<\/p>\n<h3>4. URL Rewrite<\/h3>\n<p>URL rewrite basically selects the clean URL and converts it to actual paths leading to code. It must have the below components:<\/p>\n<p>\u2022 A pre-defined rewrite rule.<br \/>\n\u2022 A pattern \u2013 the pattern provided will act as a matching reference with the URL, the user enters.<br \/>\n\u2022 Rewriting lines \u2013 it will call the path that should be called by the server at that point of time.<\/p>\n<p>Now, you will write a rewrite rule which will redirect a user to About_us.html page, if the requested URL is http:\/\/ip\/Aboutus<\/p>\n<p>For successful running of rewrite rule, the rewrite engine should be on. Run the below command at the start of the .htaccess file.<\/p>\n<pre class=\"lang:default decode:true \">RewriteEngine on<\/pre>\n<p>Next, add the below syntax:<\/p>\n<pre class=\"lang:default decode:true \">ReWriteRule ^About_us$ Aboutus.html [NC]<\/pre>\n<p>Let\u2019s understand the syntax in a simple way:<\/p>\n<p>\u2022 About_us is the pattern that will be redirected to About_us.html when encountered and matched.<br \/>\n\u2022 NC is a flag for making the rule case insensitive.<br \/>\n\u2022 ^ Indicates that the text immediately after the IP address is matched.<\/p>\n<p>When you combine the two lines it would appear as below in the .htaccess file:<\/p>\n<pre class=\"lang:default decode:true \">ReWriteEngine on\r\nReWriteRule ^About_us$ Abouts_us.html [NC]<\/pre>\n<p>That\u2019s it! You have successfully created a mod_rewrite rule!<\/p>\n<h3>Wrap Up<\/h3>\n<p>From this, you have seen that easy, clean and user-friendly URLs are key for any successful website. Having keywords is very important for memorable URLs as well as SEO too! Hundreds of rules can be created and written.<\/p>\n<p>We hope you will use mod_rewrite for good purpose.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache\u2019s mod_rewrite offers an effective and easy way for manipulating URLs. URLs are manipulated from the server side. In simple terms, mod_rewrite helps clean and user-friendly URLs to convert into websites. As per the name, it performs rewriting on URL. It can be a great way for cleaning up your website\u2019s URLs. In this tutorial, [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[776,778,777],"class_list":["post-7343","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-vps-faq","tag-mod_rewrite","tag-mod_rewrite-on-vps","tag-setup-mod_rewrite"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Discover the Steps to Set Up mod-rewrite in Simple Steps<\/title>\n<meta name=\"description\" content=\"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Discover the Steps to Set Up mod-rewrite in Simple Steps\" \/>\n<meta property=\"og:description\" content=\"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-07T10:59:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-13T11:55:39+00:00\" \/>\n<meta name=\"author\" content=\"Pallavi Godse\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pallavi Godse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\"},\"author\":{\"name\":\"Pallavi Godse\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\"},\"headline\":\"Learn to Set Up mod-rewrite in Simple Steps\",\"datePublished\":\"2019-06-07T10:59:52+00:00\",\"dateModified\":\"2019-06-13T11:55:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\"},\"wordCount\":804,\"commentCount\":0,\"keywords\":[\"mod_rewrite\",\"mod_rewrite on VPS\",\"setup mod_rewrite\"],\"articleSection\":[\"VPS FAQ\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\",\"name\":\"Discover the Steps to Set Up mod-rewrite in Simple Steps\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#website\"},\"datePublished\":\"2019-06-07T10:59:52+00:00\",\"dateModified\":\"2019-06-13T11:55:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\"},\"description\":\"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.in\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn to Set Up mod-rewrite in Simple Steps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.in\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\",\"name\":\"Pallavi Godse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3602d0ac1ab89332aea8205dcf474af4ff4eb319cfd584544038908cd5e4c966?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3602d0ac1ab89332aea8205dcf474af4ff4eb319cfd584544038908cd5e4c966?s=96&d=blank&r=g\",\"caption\":\"Pallavi Godse\"},\"description\":\"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.\",\"sameAs\":[\"https:\/\/www.milesweb.in\"],\"url\":\"https:\/\/www.milesweb.in\/hosting-faqs\/author\/pallavi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Discover the Steps to Set Up mod-rewrite in Simple Steps","description":"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/","og_locale":"en_US","og_type":"article","og_title":"Discover the Steps to Set Up mod-rewrite in Simple Steps","og_description":"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.","og_url":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2019-06-07T10:59:52+00:00","article_modified_time":"2019-06-13T11:55:39+00:00","author":"Pallavi Godse","twitter_misc":{"Written by":"Pallavi Godse","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#article","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/"},"author":{"name":"Pallavi Godse","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945"},"headline":"Learn to Set Up mod-rewrite in Simple Steps","datePublished":"2019-06-07T10:59:52+00:00","dateModified":"2019-06-13T11:55:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/"},"wordCount":804,"commentCount":0,"keywords":["mod_rewrite","mod_rewrite on VPS","setup mod_rewrite"],"articleSection":["VPS FAQ"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/","url":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/","name":"Discover the Steps to Set Up mod-rewrite in Simple Steps","isPartOf":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#website"},"datePublished":"2019-06-07T10:59:52+00:00","dateModified":"2019-06-13T11:55:39+00:00","author":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945"},"description":"The article provides information about what is mod_rewrite, its use and steps to set up mod_rewrite on a VPS running Apache.","breadcrumb":{"@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/setup-mod-rewrite\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.in\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"Learn to Set Up mod-rewrite in Simple Steps"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.in\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.in\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945","name":"Pallavi Godse","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.milesweb.in\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3602d0ac1ab89332aea8205dcf474af4ff4eb319cfd584544038908cd5e4c966?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3602d0ac1ab89332aea8205dcf474af4ff4eb319cfd584544038908cd5e4c966?s=96&d=blank&r=g","caption":"Pallavi Godse"},"description":"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.","sameAs":["https:\/\/www.milesweb.in"],"url":"https:\/\/www.milesweb.in\/hosting-faqs\/author\/pallavi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/7343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=7343"}],"version-history":[{"count":1,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/7343\/revisions"}],"predecessor-version":[{"id":7344,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/posts\/7343\/revisions\/7344"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=7343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=7343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.in\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=7343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}