Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess not being read

Tags:

.htaccess

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 .

like image 822
user1411837 Avatar asked Aug 06 '12 07:08

user1411837


People also ask

Why is my .htaccess file not working?

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.

How do I make sure .htaccess is working?

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.

How do I know if htaccess is read?

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.

How do I read .htaccess file?

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.


2 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.

like image 74
gmc Avatar answered Oct 21 '22 15:10

gmc


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
like image 22
Morgan Wilde Avatar answered Oct 21 '22 17:10

Morgan Wilde