Apache 2.4 server not reading .htaccess file - apache

We are setting up a new server, where we have installed Apache 2.4 and PHP 7.2. In our code structure we have an .htaccess file, but Apache is not accessing it.
We have modify the httpd.conf file and enabled the mod_rewrite and set
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And restart Apache after this, but it is not picking .htaccess file from location - htdocs/myProject/.htaccess

strange but its work for me, in httpd.conf file, I have change -
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
to
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
And it work for me.
Thanks

Related

VirtualHosts in Apache using xampp

I have an application in Python to which I access via an html document running in Apache, using xampp. I have to type "desktop-6oirdq3:8081/db.html" from a remote device to get to the file. I want to use a friendlier URL and easier to remember. For that, I'm trying to create a VirtualHost in Apache. The path for the file is:
C:/xampp/htdocs/Dashboard/db.html
These are some lines of my httpd.conf:
Listen 8081
DocumentRoot "C:/xampp/htdocs/Dashboard"
<Directory "C:/xampp/htdocs/Dashboard">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
default.php default.pl default.cgi default.asp default.shtml default.html
default.htm \
home.php home.pl home.cgi home.asp home.shtml home.html home.htm index.py app.py
</IfModule>
Include conf/extra/httpd-vhosts.conf
ScriptInterpreterSource Registry-Strict
In the httpd-vhosts.conf I have:
NameVirtualHost 192.168.1.134:8081
<VirtualHost 192.168.1.134:8081>
DocumentRoot "C:/xampp/htdocs/Dashboard"
ServerName dashboard.com
</VirtualHost>
<Directory "C:/xampp/htdocs/Dashboard">
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
Require all granted
</Directory>
And finally in the hosts file:
::1 localhost
192.168.1.134 dashboard.com
The thing is, when I activate Apache, and type "dashboard.com" in the searchbar, it says "This site can't be reached". I have no idea what is wrong. Followed several tutorials but don't work it out. Do you have any idea? If you need more code I'll provide it
Thank you!

Yii2 Advance application show directory listing instead web view

I just copy my Yii2 advanced app from windows to linux.
PHP, Apache2, etc already installed successfully.
But when I got to localhost/myweb It show directory listing instead of web view.
Here is my apache2.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/myweb/frontend/web/
</VirtualHost>
Here is myweb/.htaccess
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^administrator(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1
How I can show web view, instead of directory listing?
Where I doing wrong?
Thanks in advance.
On Linux, you may need to modify the httpd.conf file located at:
/etc/httpd/conf/httpd.conf
you should change the following lines from:
<Directory "/var/www/html">
AllowOverride None
</Directory>
to
<Directory "/var/www/html">
AllowOverride All
</Directory>
and then restart the httpd service

DirectorySlash Off doesn't work

I'm using apache 2.4.7
This is my virtualhost's config:
DocumentRoot /var/www/login
ServerName login.mydomain.com
<Directory "/var/www/login">
allow from all
AllowOverride All
Options +Indexes
DirectoryIndex index.html index.php
DirectorySlash Off
Require all granted
</Directory>
In my /var/www/login directory, I have a directory called freeseat and in there, there's the index.php file, so it's full location is /var/www/login/freeseat/index.php
When I try to access it through the following link (domain replaced), it redirects to the same URL with a trailing slash:
http://login.mydomain.com/freeseat -> http://login.mydomain.com/freeseat/
Why isn't the DirectorySlash Off working? I tried to put it in .htaccess, but that didn't help either.
Thanks a lot for your help,
David
First of all, you vHost won't work if you don't use the directive.
This works:
<VirtualHost *:80>
DocumentRoot /var/www/login
ServerName login.mydomain.com
<Directory "/var/www/login">
Allow from all
AllowOverride All
Options +Indexes
DirectoryIndex index.html index.php
DirectorySlash Off
Require all granted
</Directory>
ErrorLog /var/www/login/error.log
</VirtualHost>
To answer you question: DirectorySlash works as expected.
Also see apache documentation for mod_dir, especially the red box called "Security Warning" of section "DirectorySlash".
Tip: always use not publicly accessible error logs to determine the root of evil. :)
Edit #1:
I think I might have misunderstood your question. You want to access /var/www/login/freeseat/index.php through http://login.mydomain.com/freeseat (w/o trailing slash).
Then, drop the freeseat folder and use index.php as var/www/login/freeseat.php and create a RewriteRule in the /var/www/login/.htaccess file (mod_rewrite must be active):
RewriteEngine On
RewriteRule ^freeseat$ freeseat.php
Also, drop
Options +Indexes
DirectoryIndex index.html index.php
from your vHost configuration. It isn't needed anymore.

Apache2 on Ubuntu 14.04 won't load index.php

Using the following posts:
Ubuntu 14.04 apache2 configuration problems
.htaccess file not working on Ubuntu 14.04 with apache2
Apache doesn't execute script of index.php in root automatically
I've changed my /etc/apache2/apache2.conf file to be the following:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory
And I've created the file /var/www/html/.htaccess to be the following:
DirectoryIndex Index.php index.php Index.html index.html Index.htm index.htm
When I go to my site, the default page is still the (It Works!) index.html file.
How do I configured Apache to give priority to index.php?
Is your DocumentRoot /var/www/ or /var/www/html/ (the latter is where you say you have your .htaccess file)??
If the .htaccess is in /var/www/html/ than I'm gonna guess you need to update your Apache config to be:
<Directory /var/www/html/>

.htaccess not working on my Ubuntu 14.04 Distribution

I have just configured my LAMP stack on my Ubuntu 14.04 distribution and want to set .htaccess up to serve a website.
I followed the tutorial https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file and configured a virtual host for my domain, however I am still unable to use the .htaccess file in my projects root, whenever I try to serve a page I get a 404 error.
The .conf file for my domain looks like:
<VirtualHost *:80>
ServerAdmin alexmk92#live.co.uk
ServerName alexsims.me
ServerAlias www.alexsims.me
DocumentRoot /var/www/alexsims.me
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/alexsims.me>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried to change AllowOverride None to AllowOverride All but that caused an internal 500 error even after enabling mod_rewrite.
Regards,
Alex.
EDIT: .htaccess contents
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alexsims.me [NC]
RewriteRule ^(.*)$ http://www.alexsims.me/$1 [L,R=301,NC]
#--- Rewrite PHP files clean URL
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)$ ?page=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ ?page=$1&id=$2 [NC,L]
I have same issue with Ubuntu 15.10.
I solved this way.
First you need to enable rewrite module:
sudo a2enmod rewrite
sudo gedit /etc/apache2/apache2.conf
and replace
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And finally
sudo service apache2 reload
Actually what is difference between restart and reload !
restart= stop + start
reload = remain running + re-read configuration files.
We have changed configuration so we need to reload configuration.
It should help someone as I have wasted 4 hours :)
Try
Require all granted
in place of
Order allow,deny
allow from all
See the upgrade documentation for more info:
In 2.2, access control based on client hostname, IP address, and other
characteristics of client requests was done using the directives
Order, Allow, Deny, and Satisfy.
In 2.4, such access control is done in the same way as other
authorization checks, using the new module mod_authz_host. The old
access control idioms should be replaced by the new authentication
mechanisms, although for compatibility with old configurations, the
new module mod_access_compat is provided.
AllowOverride None
That's your problem, right there. The 500 error you're getting could mean that your .htaccess file is malformed - start
See http://httpd.apache.org/docs/current/mod/core.html#allowoverride
You should check if the directives you use in .htaccess are enabled.
For example if you use RewriteEngine you should have apache module rewrite enabled:
cat /etc/apache2/mods-available/rewrite.load
a2enmod rewrite
service apache2 restart
For ExpiresActive directive you should enable apache module expires:
cat /etc/apache2/mods-available/expires.load
a2enmod expires
service apache2 restart
etc.