{"id":1302,"date":"2017-04-02T08:58:35","date_gmt":"2017-04-02T03:28:35","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1302"},"modified":"2026-09-28T20:21:07","modified_gmt":"2026-09-28T14:51:07","slug":"enable-mod-rewrite-module-apache-2-4-ubuntu","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/enable-mod-rewrite-module-apache-2-4-ubuntu\/","title":{"rendered":"How to Enable the mod_rewrite Module on Apache 2.4"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date<\/strong>: April 1, 2017<br><strong>Last Updated<\/strong>: September 28, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache&#8217;s <code>mod_rewrite<\/code> module is commonly used to create URL redirects and rewrite rules. It is also required for <code>.htaccess<\/code> rewrite rules to work correctly on an Apache web server. This guide explains how to enable the <code>mod_rewrite<\/code> module on Apache 2.4 and configure the required <code>AllowOverride<\/code> setting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before enabling the <code>mod_rewrite<\/code> module, ensure that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apache 2.4 is installed on the server.<\/li>\n\n\n\n<li>You have root or sudo access to the server.<\/li>\n\n\n\n<li>The website&#8217;s document root is identified.<\/li>\n\n\n\n<li>You have permission to modify the Apache virtual host configuration.<\/li>\n\n\n\n<li>It is recommended to take a backup of the Apache configuration before making changes.<\/li>\n<\/ul>\n\n\n<h2>Implementation:<\/h2>\n<p>Log in to the server as root.<\/p>\n<p>Execute the following command to enable the mod_rewrite module.<\/p>\n<p><code>a2enmod rewrite<\/code><\/p>\n<p>Restart the Apache service to take effect.<\/p>\n<p><code>service apache2 restart<\/code><\/p>\n<p>If you followed the above post, there will be a default configuration file, <em>000-default.conf.\u00a0<\/em>Open the file and add the following content.<\/p>\n<p><code>vi \/etc\/apache2\/sites-enabled\/000-default.conf<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;Directory \/var\/www\/html\/&gt;\n                Options Indexes FollowSymLinks MultiViews\n                AllowOverride All\n                Order allow,deny\n                allow from all\n&lt;\/Directory&gt;<\/pre>\n<p>If the document root is different from<em>\/var\/www\/html\u00a0<\/em>then replace it with the appropriate directory.<\/p>\n<p>Restart the Apache service for the changes to take effect.<\/p>\n<p><code>service apache2 restart<\/code><\/p>\n<h4>Verification:<\/h4>\n<p>1. Execute the command below and look for the rewrite module in the output.<\/p>\n<p><code>apachectl -M|grep rewrite<\/code><\/p>\n<p>2. Create a <em>.htaccess<\/em> file in the directory and add a simple rewrite rule.<\/p>\n<p><code>vi\u00a0\/var\/www\/html\/.htaccess<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">RewriteEngine on<\/pre>\n<p>Access the domain or IP address (<em>http:\/\/IPAddress)\u00a0<\/em>in the browser. If you see a <strong>500<\/strong> Internal Server Error, then there is a problem with the rewrite module.<\/p>\n<p>Look for any errors while accessing the page in the browser using the command. If you see any error related to <em>Rewrite<\/em><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><em>,<\/em> <\/span>then there is a problem with the rewrite module.<\/p>\n<p><code>tail -fn0 \/var\/log\/apache2\/error_log<\/code><\/p>\n<p>In case of any issue, please comment here.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Enabling <code>mod_rewrite<\/code> allows Apache to process URL rewrite rules and <code>.htaccess<\/code> configurations. By enabling the module, setting <code>AllowOverride All<\/code> for the appropriate document root, and restarting Apache, rewrite rules can be used successfully. The verification steps can be used to confirm that the module is enabled and identify any configuration-related issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Is <code>mod_rewrite<\/code> available by default in Apache 2.4?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>mod_rewrite<\/code> module is included with Apache 2.4, but it may not be enabled by default on some Linux distributions. You can enable it using <code>a2enmod rewrite<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Is <code>AllowOverride All<\/code> safe to use for every Apache directory?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is generally better to enable only the directives required by the application. <code>AllowOverride All<\/code> permits <code>.htaccess<\/code> to override a broad range of Apache settings, so it should be applied only where required.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. What should I do if <code>.htaccess<\/code> rewrite rules are not working after enabling <code>mod_rewrite<\/code>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that <code>mod_rewrite<\/code> is enabled, <code>AllowOverride<\/code> permits <code>.htaccess<\/code> rules for the document root, and the <code>.htaccess<\/code> syntax is correct. You can also check the Apache error log for configuration or rewrite-related errors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-enable-mod_rewrite-for-apache-in-centos\/\"> How to enable mod_rewrite for Apache in CentOS<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business?. Our experts can help with\u00a0web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team\u00a0<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: April 1, 2017Last Updated: September 28, 2026 Introduction Apache&#8217;s mod_rewrite module is commonly used to create URL redirects [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[278,274],"class_list":["post-1302","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-apache","tag-ubuntu","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-l0","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1302"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1302\/revisions"}],"predecessor-version":[{"id":11983,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1302\/revisions\/11983"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}