Reputation: 1564
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 .
Upvotes: 13
Views: 17002
Reputation: 335
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>
Upvotes: 1
Reputation: 6820
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>
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
Upvotes: 0
Reputation: 3990
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.
Upvotes: 4
Reputation: 17333
If no matter what you put into your .htaccess
file, you don't even get an error, that means that you probably need to have
AllowOverride All
set in your site configuration.
If you're on ubuntu, the place to look for the configuration is /etc/apache2/sites-available/
. There you should find a file called default
if this is a stock install of the default LAMP stack (https://help.ubuntu.com/community/ApacheMySQLPHP).
The key part there is this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Now change AllowOverride None
to AllowOverride All
. After that don't forget to restart your apache like so:
$ service apache2 restart
Upvotes: 29
Reputation: 28968
As an addition to Morgan's answer, putting AllowOverride All
in your virtual host is sometimes not enough. I had this in my virtual host:
<VirtualHost *:80>
...
<Directory />
...
AllowOverride All
...
</Directory>
</VirtualHost>
You would expect this to work, wouldn't you, <Directory />
means it should be applied to everywhere on the file system. But .htaccess
was still being ignored. Restarting the server did not help. I put junk in the .htaccess file to confirm it was not being read.
My mistake was assuming a virtual host overrides the global configuration. Kind of it does: my above configuration overrides any global settings for the /
directory. But the global configuration overrides it back for /var/www/
and below. My fix is:
<VirtualHost *:80>
...
<Directory /var/www>
...
AllowOverride All
...
</Directory>
</VirtualHost>
(this assumes none of the other configuration needed to apply outside /var/www
; if it does, make a separate <Directory />
block for just that special configuration.)
Upvotes: 10