How to enable mod_rewrite for Apache 2.2

I've got fresh install of Apache 2.2 on my Vista machine, everything works fine, except mod rewrite.

I've uncommented

LoadModule rewrite_module modules/mod_rewrite.s

but none of my rewrite rules works, even simple ones like

RewriteRule not_found %{DOCUMENT_ROOT}/index.php?page=404

All the rules I'm using are working on my hosting, so they should be ok, so my question is, is there any hidden thing in apache configuration, that could block mod rewrite?

In order to use mod_rewrite you can type the following command in the terminal:

sudo a2enmod rewrite

Restart apache2 after

sudo /etc/init.d/apache2 restart

or

sudo service apache2 restart

or as per new unified System Control Way

sudo systemctl restart apache2

Then, if you'd like, you can use the following .htaccess file.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

The above .htaccess file (if placed in your DocumentRoot) will redirect all traffic to an index.php file in the DocumentRoot unless the file exists.

So, let's say you have the following directory structure and httpdocs is the DocumentRoot

httpdocs/
    .htaccess
    index.php
    images/
        hello.png
    js/
        jquery.js
    css/
        style.css
includes/
    app/
        app.php

Any file that exists in httpdocs will be served to the requester using the .htaccess shown above, however, everything else will be redirected to httpdocs/index.php. Your application files in includes/app will not be accessible.

How to enable mod_rewrite on Apache on CentOS – E2E Networks , How do you check mod_rewrite is enabled or not CentOS? How to enable mod_rewrite on Apache on CentOS. Step 1: Check if the module exists. Before enabling the module mod_rewrite, we need to check if the module is already loaded in the httpd file Step 2: Check if the module is loaded. Step 3: Configure httpd.conf file.

For my situation, I had

RewriteEngine On

in my .htaccess, along with the module being loaded, and it was not working.

The solution to my problem was to edit my vhost entry to inlcude

AllowOverride all

in the <Directory> section for the site in question.

Install and Configure mod_rewrite for Apache on CentOS 7, it by editing 00-base. conf file located in /etc/httpd/conf. modules. Open terminal and typin a2enmod rewrite, It will enable your mod_rewrite module for Apache. Then go to /etc/apache2/sites-available and edit default file. (For this you must have writable permissions to this file and sites-available folder.)

Try setting: AllowOverride All.


Second most common issue is not having mod rewrite enabled: a2enmod rewrite and then restart apache.

Apache Module mod_rewrite, provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Mod_rewrite is famous for translating human-readable URLs in dynamic websites. This makes the URL’s look cleaner and friendly in websites. In this guide, we are going to cover the steps of enabling mod_rewrite on your Apache Server running on an Ubuntu 18.04 VPS.

If non of the above works try editing /etc/apache2/sites-enabled/000-default

almost at the top you will find

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

Change the AllowOverride None to AllowOverride All

this worked for me

mod_rewrite, Introduction; Requirements; Install Apache; Enable mod_rewrite Module; Enable .htaccess File; Configure Rewrite Module; Redirect www to  Step 1 — Enabling mod_rewrite. First, we need to activate mod_rewrite. It’s available but not enabled with a clean Apache 2 installation. sudo a2enmod rewrite This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache. sudo systemctl restart apache2 mod_rewrite is now

In Ubuntu:

Run:

a2enmod rewrite

and then:

service apache2 restart

mod_rewrite will now be enabled!

How to Rewrite URLs with mod_rewrite for Apache on Ubuntu 18.04 , In this tutorial, you'll enable mod_rewrite and use .htaccess files to create a basic URL redirection, and then explore a couple of advanced use  I referred to this link but have not been able to solve the problem: How to enable mod_rewrite for Apache 2.2. When I type in: mod_rewrite I get this error: bash: mod_rewrite: command not found This line is not commented: LoadModule rewrite_module modules/mod_rewrite.s Also, when I try to restart Apache using the following command:

Making sure .htaccess and mod_rewrite are working as they should , If you do not see an 'Internal Server Error', your Apache setup ignores the this may be done on different setups: How to enable mod_rewrite for Apache 2.2. To enable mod_rewrite, I went through the below steps: Find and open the file .http.conf. This will be located in your Apache install folder. For me, the full path was C:Program Files (x86)Apache Software FoundationApache2.2conf; Make a backup of http.conf which you can restore from, if anything were to go wrong

Enabling mod_rewrite on Windows Apache for URL rewriting, A tutorial demonstrating how to enable mod_rewrite which will allow a website running on a WAMP stack to use a local .htaccess file for URL  With Apache installed and the mod_rewrite module enabled, we’re ready to configure the use of a .htaccess file. Step 3 – Setting up a .htaccess File A .htaccess file allows the defining of directives for Apache, including a RewriteRule , on a per domain basis without altering server configuration files.

Configuring mod_rewrite for Windows with Apache, Go to Styling and Front-end Settings to switch URL Rewriting ON and save the new settings. Open a KMP front-end page in your browser to check 

Comments
  • actually the problem was that i had wrong path, because ${DOCUMENT_ROOT} pointed me to root directory which was ok on hosting, but wrong on local, so the problem wasnt just RewriteEngine On, which i already had ..
  • Can you please change the accepted answer to this one? The author of current accepted answer has admitted it's not good enough.
  • How to enable mod_rewrite in Ubuntu 12.04 LTS (should work in Debian too). This shows installation AND activation, the tutorials below surprisingly don't do :(
  • I would strongly advise everybody that wants to enable mod_rewrite directives in .htacces files to use AllowOverride FileInfo instead of allowing everything, as ALL the answers on this page suggest. Sad to see all these answers take the as-long-as-it-works-it's-okay-approach instead of trying to understand the consequences of the proposed 'solution'. Try to understand what you are doing on your server and how to limit the privileges you just gave away with AllowOverride All. RTFM!, it is quit clear on the subject.
  • @Black It's in the Apache config file named httpd.conf. In my PC, it is in the directory C:\xampp\apache\conf, because I installed Apache with XAMPP.
  • The ideas here are correct for a UNIX CLI but the commands only work for a Debian based Linux distributions and not a Windows environment of the OP.
  • a2enmod rewrite did the job
  • Further note: you also need to make sure that your site's configuration has AllowOverride All in order for the .htaccess file to be read at all.
  • @Dennis you can use a2dismod rewrite
  • how can I use a2enmod rewrite in windows?
  • Indeed, even with a2enmod rewrite & RewriteEngine On in the .htaccess - the existence of AllowOverride all in the VirtualHost file will prevent it from working - this is what caught me out, changing it to AllowOverride all worked like a charm :)
  • beginner here.. where's the VirtualHost file ?