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 .
Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.
Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.
The simplest way to test if apache uses your . htaccess file, or if it otherwise ignores it, is to intentionally break it. Edit the . htaccess file, so the first line reads 'Test.
The . htaccess file is a powerful website file that controls high-level configuration of your website. On servers that run Apache (a web server software), the . htaccess file allows you to make changes to your website's configuration without having to edit server configuration files.
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 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With