4

I put an .htaccess file in the directory where I am hosting my site. /var/www/html However it isnt being read.

I tried changing the AlowOverride in the httpd config file

<Directory /var/www/html> 
  Options Indexes FollowSymLinks MultiViews 
  AllowOverride All 
  Order allow,deny 
  allow from all 
</Directory>

And my .htaccess works on my local server, however when I try it on my hosted server it doesnt read it at all.

Here is my .htaccess file for reference.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^([0-9]+)$ index.php?week=$1 
RewriteRule ^([0-9]+)/$ index.php?week=$1
user2989367
  • 405
  • 3
  • 11
  • 19

3 Answers3

1

Your .htaccess file could be being ignored for multiple reasons, so I would encourage you trying the following steps to determine the cause of your issue:

  1. Can Apache read .htaccess? Check file permissions are set to something proper such as 0640 and make sure its group owner is www-data.
  2. Is rewrite_mod enabled? Without it, RewriteEngine will not work. You can enable rewrites by running 2enmod rewrite with root permissions.
  3. Have you restarted Apache since the last time you changed httpd.conf? In case not, restart it by running /etc/init.d/apache2 restart, again with root permissions.

If your website is still not working properly after trying these steps, check your Apache error logs. They're usually located in /var/log/apache2/error.log.

josemmo
  • 6,523
  • 3
  • 35
  • 49
0

The easiest way to check if .htaccess file is loaded by apache is to add a line with wrong syntax into it. You should get 500 Internal Server Error after that if .htaccess file is being read. Remove this test line after that.

Then you may check that mod_rewrite is loaded. After that you may check that rewrite rules are working as intended with htaccess tester

Alexander Zotov
  • 156
  • 1
  • 5
  • I already tried that indeed it isn’t being read, I’m trying to find a solution to make sure it is read. Like I said it woks on my local server just not my hosted server. – user2989367 Oct 02 '18 at 00:12
  • Did you checked the difference between httpd config files at local server and hosted server? Did both servers has /var/www/html as a DocumentRoot and it does exist at hosted server? – Alexander Zotov Oct 02 '18 at 00:17
  • The only difference as far as I know is as I mentioned before, I didnt change anything else – user2989367 Oct 02 '18 at 00:20
  • You can try to add full content of httpd configs at your hosted server to your question (with sensitive information replaced with asterisks). You can also restart apache and check apache error_log for errors. – Alexander Zotov Oct 02 '18 at 00:26
0

Hi Can you please review if you had uncheck the below options -

enter image description here

Peter
  • 663
  • 1
  • 7
  • 15