{"id":13,"date":"2018-04-08T07:24:55","date_gmt":"2018-04-08T01:54:55","guid":{"rendered":"https:\/\/www.onlinenote.in\/linux\/?p=13"},"modified":"2019-09-18T10:11:55","modified_gmt":"2019-09-18T04:41:55","slug":"how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/","title":{"rendered":"How To Set Up mod_rewrite for Apache on Ubuntu 18.04"},"content":{"rendered":"<p>Prerequisites:-<\/p>\n<p>Make user Apache 2 installed on your server &#8211; <a href=\"https:\/\/www.onlinenote.in\/linux\/install-lamp-in-ubundu\/\">How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04<\/a>.<\/p>\n<h5>Step 1 \u2014 Installing Apache<\/h5>\n<pre class=\"lang:default decode:true \">sudo apt-get update\r\nsudo apt-get install apache2<\/pre>\n<h5>Step 2 \u2014 Enabling mod_rewrite<\/h5>\n<pre class=\"lang:default decode:true \">sudo a2enmod rewrite\r\nsudo service apache2 restart<\/pre>\n<h5>Step 3 \u2014 Setting Up .htaccess<\/h5>\n<p>In this section, we will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without accessing server configuration files. For this reason, .htaccess is critical to your web application&#8217;s security. The period that precedes the filename ensures that the file is hidden. We will need to set up and secure a few more settings before we can begin. First, allow changes in the .htaccess file. Open the default Apache configuration file using nano or your favorite text editor.<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/etc\/apache2\/sites-enabled\/000-default.conf<\/pre>\n<p>Inside that file, you will find the\u00a0block on line 1. Inside of that block, add the following block:<\/p>\n<pre class=\"lang:default decode:true\"># \/etc\/apache2\/sites-available\/default\r\n&lt;VirtualHost *:80&gt;\r\n    &lt;Directory \/var\/www\/html&gt;\r\n        Options Indexes FollowSymLinks MultiViews\r\n        AllowOverride All\r\n        Require all granted\r\n    &lt;\/Directory&gt;\r\n\r\n    . . .\r\n&lt;\/VirtualHost&gt;<\/pre>\n<h5>Now, create the .htaccess file.<\/h5>\n<pre class=\"lang:default decode:true \">sudo nano \/var\/www\/html\/.htaccess<\/pre>\n<p>Add this first line at the top of the new file to activate the RewriteEngine.<\/p>\n<pre class=\"lang:default decode:true \">\/var\/www\/html\/.htaccess\r\nRewriteEngine on<\/pre>\n<p>Save and exit the file. To ensure that other users may only read your .htaccess, run the following command to update permissions.<\/p>\n<pre class=\"lang:default decode:true \">sudo chmod 644 \/var\/www\/html\/.htaccess<\/pre>\n<h5>Step 4 \u2014 Setting Up Files<\/h5>\n<p>In this section, we will set up a basic URL rewrite, which converts pretty URLs into actual paths to code. Specifically, we will allow users to access example.com\/about. We will begin by creating a file named about.html.<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/var\/www\/html\/about.html<\/pre>\n<p>Copy the following code into the HTML page.<\/p>\n<pre class=\"lang:default decode:true\"># \/var\/www\/html\/about.html\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;About Us&lt;\/title&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n        &lt;h1&gt;About Us&lt;\/h1&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>You may access your web application at your_server_ip\/about.html or example.com\/about.html. Now notice that only about.html is accessible; if you try to access your_server_ip\/about, you will get a Not Found error. We would like users to access about instead. Our rewrite rules will allow this very functionality.<\/p>\n<pre class=\"lang:default decode:true \">sudo nano \/var\/www\/html\/.htaccess<\/pre>\n<p>After the first line, add the following.<\/p>\n<pre class=\"lang:default decode:true \">\/var\/www\/html\/.htaccess\r\nRewriteRule ^about$ about.html [NC]<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites:- Make user Apache 2 installed on your server &#8211; How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04. Step 1 \u2014 Installing Apache sudo apt-get update sudo apt-get install apache2 Step 2 \u2014 Enabling mod_rewrite sudo a2enmod rewrite sudo service apache2 restart Step 3 \u2014 Setting Up .htaccess In this section, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux<\/title>\n<meta name=\"description\" content=\"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.\" \/>\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.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux\" \/>\n<meta property=\"og:description\" content=\"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:site_name\" content=\"linux\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-08T01:54:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-18T04:41:55+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/\",\"url\":\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/\",\"name\":\"How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/linux\/#website\"},\"datePublished\":\"2018-04-08T01:54:55+00:00\",\"dateModified\":\"2019-09-18T04:41:55+00:00\",\"author\":{\"@id\":\"\"},\"description\":\"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/linux\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Set Up mod_rewrite for Apache on Ubuntu 18.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/linux\/\",\"name\":\"linux\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/linux\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux","description":"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.","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.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/","og_locale":"en_US","og_type":"article","og_title":"How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux","og_description":"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.","og_url":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/","og_site_name":"linux","article_published_time":"2018-04-08T01:54:55+00:00","article_modified_time":"2019-09-18T04:41:55+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/","url":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/","name":"How To Set Up mod_rewrite for Apache on Ubuntu 18.04 - linux","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/linux\/#website"},"datePublished":"2018-04-08T01:54:55+00:00","dateModified":"2019-09-18T04:41:55+00:00","author":{"@id":""},"description":"We will setup a .htaccess file for simpler rewrite rule management. A .htaccess file allows us to modify our rewrite rules without server configuration file.","breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/linux\/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-18-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/linux\/"},{"@type":"ListItem","position":2,"name":"How To Set Up mod_rewrite for Apache on Ubuntu 18.04"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/linux\/#website","url":"https:\/\/www.onlinenote.in\/linux\/","name":"linux","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/linux\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":2,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/13\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}