How to enable .htaccess in apache2 (ubuntu 18.04) - php

I'm trying to use .htaccess on my project on apache2 using ubuntu 18.04.
The tutorials I saw said that I have to change apache2.conf as:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all denied
</Directory>
To:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all denied
</Directory>
After change it, I make my own htaccess on project but it doesn't work.
I want browser prevent user to go backward and browsing project directories and my computer directories using URL ../../../../
Ex: localhost/project/index.php/../../../../
How can I use my .htaccess in my project?, knowing that there is no default .htaccess file !
And how to prevent user for browsing directories using ../../ in url ???

Related

How can i block direct access to specific folder?

There is my problem, i have an img tag, src gets image from icon/ folder and i need to disable direct link access to that folder and content inside that when user type something like 'mywebsite.com/icon/logo.png', using htaccess, but allow content inside src attribute to get and display it without 403 error message 'access denied' in browser console, i made lot of research but nothing helped me, if i missing something please provide your opinions thanks.
my .htaccess code is here:
<IfModule mod_rewrite.c>
<If "%{HTTP_HOST} == 'http://mywebsite.com/icon/'">
deny from all
</If>
<Else>
allow from all
</Else>
</IfModule>
The best way to do this is disable it with webserver apache2. In my 14.X Ubuntu - open /etc/apache2/apache2.conf you have to change from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
now just restart apache.
to restart apache2 run:
sudo service apache2 restart
This will disable directory listing from all folder that apache2 serves.

Forbidden: You don't have permission to access /abcd/ on this server

I am running a CentOS 6.9 OS. I have Apache/2.2.15 (CentOS) Server running. I have a cakephp 2 application that I want to run here. I have an index.php file inside /var/www/html that runs perfectly. I have another folder called test inside /var/www/html.
Inside that folder there is an index.php file. Test folder also runs perfectly. But whenever I try to run the cakephp application from the browser I get the message I don't have permission to access that folder. The cakephp application has 0777 permission. Inside my /etc/httpd/conf/httpd.conf file there is written -
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
So I don't know what I am doing wrong and what more I can do.
hi dude please find and edit httpd.conf file, which is in /etc/httpd/conf/httpd.conf. and paste the code below
<Directory "/">
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
<Directory "/home/">
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
Then kindly restart the server if the problem still appear
disable the seLinux in /etc/selinux/config change SELINUX=disabled and restart the server it again hope it works now ^_^
restorecon -r /var/www/html does the job
I got the answer from here. https://www.centos.org/forums/viewtopic.php?t=6834

Set up a local server on an external hard drive - Forbidden error

I have a Mac OSX El Capitan operating system. Since my laptop has limited space, I am trying to set up a local server on my 1TB external hard drive with the url http://media.database/, and that uses PHP. I have set it up the best I know how, but when I go to the page, it says "Forbidden You don't have permission to access /index.php on this server."
I have set apache and host files as best I know how, but I'm still pretty new to this sort of thing. I have listed my updates to those files below and restarted the apache server using sudo apachectl restart, which has gotten me this far. Can someone enlighten me on what I might be missing. All help is greatly appreciated.
/etc/apache2/httpd.conf
<VirtualHost *:80>
ServerName media.database
DocumentRoot "file:///Volumes/DBTARA/media/"
<Directory "file:///Volumes/DBTARA/media/">
DirectoryIndex index.php index.html
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/hosts
127.0.0.1 media.database
/etc/apache2/users/vmbmacintosh.conf
<Directory "file:///Volumes/DBTARA/media/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
/etc/apache2/httpd.conf
I attempted to add the following DocumentRoot after the one I already have, but that made my other local servers inaccessible and kept the external one as forbidden.:
DocumentRoot "file:///Volumes/DBTARA/media"
<Directory "file:///Volumes/DBTARA/media">
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride None
Require all granted
</Directory>
Thanks again in advance for any assistance.

Local Host forbidden error and htaccess issue

I have spent a lot of time and read for the whole day to use htaccess in local host (Ubuntu).
I have folowed below steps.
1) Remove the '#' symbol from the line "AccessFileName .htaccess" File
: /etc/apache2/apache2.conf
2) changed, File : /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
3) Created a folder at the path /var/www/machine and placed two file index.html and demo.html
created a file .htaccess and the content of it is,
DirectoryIndex demo.html index.html
So, when I try to open the path localhost/machine it opens 'index.html' instead of "demo.html".
Also, when I have changed "AllowOverride None" to "AllowOverride All", I got a "you don't have permission to access localhost" error.

Codeigniter-for my project index.php in url was removed but after LAMP reinstallation same project without index.php in url not working(Ubuntu)

My codeigniter project was running successfully without index.php in url. It all started after I upgraded to php 5.6 from 5.4 . During upgradation I have faced several issues regarding apache which I resolved successfully one by one due to which my project is successfully running now but all its asking is index.php in url.
My attempts:
1.I have checked the mod rewrite and enabled it
2.not changed .htaccess content in my project root as it already contains the code to bypass index.php from url
3.I have tried to replace the blank file httpd.conf with
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory><Directory>
AllowOverride All
</Directory>
4.$config['index_page'] = ''
5.In /etc/apache2/sites_available/default I have
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Please help me!
May be rewrite mod is not enabled
Execute this in terminal
sudo a2enmod rewrite
sudo service apache2 restart

Categories