0

I change a line in this folder etc/apache2/apache2.conf with: AllowOverride None to AllowOverride All and I make sure AccessFileName .htaccess is set correctly.

Then enable rewrite using this command:

sudo a2enmod rewrite

Then restart apache2:

sudo service apache2 restart

This is my simple .htaccess code:

# 1 ---- Establish a custom 404 File not Found page ----

ErrorDocument 404 /index.php

# 2 ---- Prevent directory file listing in all of your folders ----

IndexIgnore *

#block hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ style/logo/logo_icon.png [NC,R,L]

Then I get this when I access the main index.php file: Forbidden

You don't have permission to access /index.php on this server. Server unable to read htaccess file, denying access to be safe Apache/2.4.12 (Ubuntu) Server at mydomain.com Port 80

The server system I am using is: Ubuntu 15.10 Server 64-Bit I cant seem to figure out where I am going wrong, I am completely new with servers also done a good amount of research however I seem to still be limited on my abilities, I would appreciate any help :)

rafcastro77
  • 997
  • 1
  • 6
  • 12
  • Well, the error message says it all: the http server is denied permission to read your `.htaccess` style file. This is a file permission issue. Note that the http server is executed under a specific user account. _That_ account needs read access to the file. So look into your file system to check what permissions the file has got and change it as required. – arkascha Feb 06 '16 at 00:00
  • Okay thanks for the help i will try that now, the main domain is under /var/www/html/ a main root would this mean I have to change tag dir from apache2.conf dir tag where this line AllowOverride All "" to "" ? – rafcastro77 Feb 06 '16 at 00:32
  • What? I can't follow there, sorry. I referred to your `.htaccess` style file, not some directory and not your http server configuration. It is that files permissions that are wrong. That is what the error message clearly says. Most likely you created that file with some user account and did not pay attention to the different permissions? You _are_ familiar with the file system permissions used in Linux systems? – arkascha Feb 06 '16 at 00:36
  • yes I completely understand on setting permission I corrected it now and every page is working now apart from this code from htaccess is not doing its job "IndexIgnore *" its meant to make any folder viewing dir forbidden as far as I know ? – rafcastro77 Feb 06 '16 at 00:40
  • No, the `IndexIgnore` command does not "make any forbidden", why do you think so? It allows to define a list of file that are not _shown_ on an automatically generated folder index. That is clearly explained in the documentation. I suggest you read it: https://httpd.apache.org/docs/2.4/mod/mod_autoindex.html#indexignore – arkascha Feb 06 '16 at 00:42
  • sorry maybe I am using the wrong words, yes as far as I know its meant to not allow people to view generated folders and files from a directory path example mydomain.com/img/ as it means to be a default for viewing all files and folders but I cant seem to make htaccess to do what its meant to do, thanks I need a great source to learn hopefully that link will clear up what I need to know – rafcastro77 Feb 06 '16 at 00:51
  • No. Sorry. That command does _not_ prevent a directory listing. That is not what I wrote and not what is documented. Don't haste like that. Take your time to read and _understand_ a written sentence before thinking you got all. – arkascha Feb 06 '16 at 00:53

0 Answers0