101

I have pushed my .htaccess files to the production severs, but they don't work. Would a restart be the next step, or should I check something else.

scunliffe
  • 57,883
  • 24
  • 118
  • 156
Jesse Hattabaugh
  • 7,359
  • 8
  • 30
  • 35

7 Answers7

96

A restart is not required for changes to .htaccess. Something else is wrong.

Make sure your .htaccess includes the statement

RewriteEngine on

which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess if it's being used. Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.

Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:

RewriteLog "logs/rewritelog"

RewriteLogLevel 7

The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.

Community
  • 1
  • 1
TomG
  • 1,701
  • 12
  • 16
  • 3
    This is a little out-dated. I ran into a similar issue and wanted to debug my rewrites for a particular use-case. I tried this method, but after a little frustration and digging, i figured out what the problem was. This is for older versions of apache. For apache2.4 > replace the RewriteLog & LogLevel above with: `LogLevel alert rewrite:trace7`. After **restarting apache**, you should see the traces in the error.log Hope that helps. [http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging](http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging) – Casper Wilkes Apr 16 '18 at 16:27
  • I use apache 2.4 on Debian, WSL and do not have a httpd config. My htaccess is not recognized. – Timo Oct 21 '20 at 10:37
52

No:

Apache allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive... Since .htaccess files are read on every request, changes made in these files take immediate effect...

gnat
  • 6,199
  • 101
  • 49
  • 71
Milen A. Radev
  • 54,001
  • 19
  • 99
  • 105
  • If you've added the username to 'Require user' in your sites-enabled file I've found empirically that you do need a restart. A graceful one does it. – Ross Feb 06 '12 at 01:10
18

From the apache documentation: Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.

PiedPiper
  • 5,377
  • 1
  • 27
  • 38
3

Only if you have not added the mod_rewrite module to Apache.

You only need to restart Apache if you change any Apache ".conf" files.

Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
ethyreal
  • 3,619
  • 2
  • 19
  • 25
2

In case of .htaccess restart is not required if it is not working probable reasons include.

  • AllowOverride May not be set which user can set inside httpd.conf or might have to contact server admin.

  • Check the file name of .htaccess it should be .htaccess not htaccess.txt see here for guide how to create one.

  • Try to use Options -Indexes or deny all kind of simple directive to see if it is working or not.

  • clear browser cache everytime if having rule for redirects or similar if previous redirect is cached it appears as if things are not working.

Community
  • 1
  • 1
Abhishek Gurjar
  • 7,152
  • 9
  • 35
  • 40
2

I have the same issue and it seems PiedPiper post about AllowOverride were most helpful. Check your httpd.conf file for "AllowOverride" and make sure it is set to All.

Dave Ip
  • 21
  • 2
0

What's in your .htaccess? RewriteRules? Check that mod_rewrite is installed and enabled.

Other stuff? Try setting AllowOverride to 'all' on that directory.

ceejayoz
  • 165,698
  • 38
  • 268
  • 341