{"id":14184,"date":"2023-05-11T18:45:30","date_gmt":"2023-05-11T18:45:30","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=14184"},"modified":"2023-09-18T15:38:40","modified_gmt":"2023-09-18T15:38:40","slug":"how-to-enable-mod_rewrite-apache-module-on-ubuntu","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-enable-mod_rewrite-apache-module-on-ubuntu\/","title":{"rendered":"How to Enable mod_rewrite Apache module on Ubuntu"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1024x768.jpg\" alt=\"How to Enable mod_rewrite Apache module on Ubuntu\" width=\"1024\" height=\"768\" class=\"alignnone size-large wp-image-16108 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1024x768.jpg 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-300x225.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1536x1152.jpg 1536w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-2048x1536.jpg 2048w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-128x96.jpg 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-420x315.jpg 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-540x405.jpg 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-720x540.jpg 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-960x720.jpg 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1140x855.jpg 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1320x990.jpg 1320w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Enable-mod_rewrite-Apache-module-on-Ubuntu-1440x1080.jpg 1440w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/768;\" \/><\/p>\n<p>The mod_rewrite module is an <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a> module that provides the ability to manipulate URLs using regular expressions. It is commonly used to create clean URLs and to redirect URLs to different pages. In this guide, we will go through the steps to enable mod_rewrite on <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-ubuntu-beginners-guide-ubuntu-linux-distro\/\">Ubuntu<\/a>.<\/p>\n<h2>Step 1: Check if mod_rewrite is Installed<\/h2>\n<p>Before enabling mod_rewrite, you need to check if it is installed on your Ubuntu machine. To do this, open a terminal and type the following command:<\/p>\n<pre>\r\napache2ctl -M | grep rewrite\r\n<\/pre>\n<p>If the mod_rewrite module is installed, you should see &#8220;rewrite_module&#8221; in the output. If it is not installed, you can proceed with the next step to install it.<\/p>\n<h2>Step 2: Install mod_rewrite<\/h2>\n<p>To install the mod_rewrite module, you can use the following command:<\/p>\n<pre>\r\nsudo a2enmod rewrite\r\n<\/pre>\n<p>This command will enable the mod_rewrite module on your Ubuntu machine.<\/p>\n<h2>Step 3: Restart Apache<\/h2>\n<p>After enabling the mod_rewrite module, you need to restart the Apache web server to apply the changes. You can do this by using the following command:<\/p>\n<pre>\r\nsudo service apache2 restart\r\n<\/pre>\n<p>This will restart the Apache web server.<\/p>\n<h2>Step 4: Configure .htaccess File<\/h2>\n<p>To use mod_rewrite, you need to configure the .htaccess file in your web root directory. You can create a .htaccess file by using the following command:<\/p>\n<pre>\r\nsudo nano \/var\/www\/html\/.htaccess\r\n<\/pre>\n<p>This command will open the .htaccess file in the nano text editor. You can add the following code to enable mod_rewrite:<\/p>\n<pre>\r\nRewriteEngine on\r\nRewriteRule ^(.*)$ index.php\/$1 [L]\r\n<\/pre>\n<p>This code will redirect all requests to the index.php file.<\/p>\n<h2>Step 5: Verify the Configuration<\/h2>\n<p>To verify that mod_rewrite is enabled and working correctly, you can test it by creating a test.php file with the following code:<\/p>\n<pre>\r\n&lt;?php\r\necho \"mod_rewrite is working\";\r\n?&gt;\r\n<\/pre>\n<p>Save the file and access it in your web browser by navigating to http:\/\/localhost\/test.php. If mod_rewrite is working correctly, you should see the message &#8220;mod_rewrite is working&#8221; on the page.<\/p>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">sudo<\/span> &#8211; a command that allows users to run programs with the security privileges of another user, typically the superuser.<\/li>\n<li><span class=\"fw-bold\">a2enmod<\/span> &#8211; a command that enables an Apache module.<\/li>\n<li><span class=\"fw-bold\">service<\/span> &#8211; a command used to control system services.<\/li>\n<li><span class=\"fw-bold\">nano<\/span> &#8211; a command-line text editor.<\/li>\n<\/ul>\n<h2>Conclusion:<\/h2>\n<p>In this guide, we have outlined the steps to enable mod_rewrite on Ubuntu. By following these steps, you can now use mod_rewrite to create clean URLs and to redirect URLs to different pages.<\/p>\n<p>If you have any questions or suggestions, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The mod_rewrite module is an Apache module that provides the ability to manipulate URLs using regular expressions. It is commonly used to create clean URLs and to redirect URLs to&#8230;<\/p>\n","protected":false},"author":6,"featured_media":16108,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1103,996,1073],"tags":[1199,2079,2053,1856],"class_list":["post-14184","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-linux","category-ubuntu","tag-apache","tag-apache-module","tag-mod_rewrite","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/14184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=14184"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/14184\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/16108"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=14184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=14184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=14184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}