.htaccess not being read

Viewed 15623

Iam trying to redirect my home page or any other page on the site to a particular php page . This is my htaccess

Redirect 301 http://test.com/info http://test.com/get_forms_data.php
Options +FollowSymlinks
RewriteEngine ON
RewriteRule ^test.php$ http://test.com/get_forms_data.php [R=301,L]

I have checked my apache server .rewrite is enabled .

It still doesnt work .

5 Answers

I was struggling with the same problem, and Darren Cook's answer gave me the definitive clue to find the solution.

My app was in some folder out of th public www path, lt's say in /opt/my_app. I couldn't create a VirtualHost, so I created a symlink in Apache's public www ponting to my folder:

/var/www/html/my_app -> /opt/my_app

The thing is, in my App's Apache config file, I was specifying:

<Directory /opt/my_app>
  AllowOverride All
</Directory>

And my .htaccess file wasn't being read. Then I saw that in Apache's configuration there was this:

<Directory /var/www/html>
  AllowOverride None
</Directory>

Then I realised that Apache config files do not care about symlinks, and therefore the general rule was being applied to my App's foler. I changed Directory to:

<Directory /var/www/html/my_app>
  AllowOverride All
</Directory>

And everything worked.

If Redirection doesn't work inspite of updating apache2.conf

According to the accepted answer, I updated AllowOverride None to AllowOverride All in the apache2.conf file, however redirection via .htaccess file was still not working for me!

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All   # did not work inspite of setting to "All"
    Order allow,deny
    allow from all
</Directory>

What worked for me...

I had to also enable module redirection

// enable module redirection
sudo a2enmod rewrite

Of course, do not to forget to restart your apache server for the changes to take effect

Reference

Assuming /var/www/html is the working directory: Change from AllowOverride None to AllowOverride All

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
Related