.htaccess not working on my Ubuntu 14.04 Distribution - apache

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.

Related

How to activate rewrite URL from apache2 with Linux

I recently transfered all my websites from Windows to KUbuntu via virtual machine. And now I can't access a part of my website that is using rewrite URL...
I've already activated rewrite module with sudo a2enmod rewrite and AllowOverride in apache2 conf and restarted apache but that still does not work...
At the start, I got 404 errors (without default.conf AllowOverride things)
And now I've got a 500 internal error. How don't know how to proceed next, I Googled that problem, but nothing helped me.
EDIT: The 500 internal error happened from my .htaccess:
Header add Access-Control-Allow-Origin "*"
My default.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
RewriteEngine on
</Directory>
</VirtualHost>
My .htaccess
Options -Indexes
RewriteEngine on
# RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
# %{HTTP_HOST} = domain
# %{REQUEST_URI} = /vl_web/...
# rewrite pages
RewriteRule ^login$ ./login.php [L]
RewriteRule ^reglement$ ./rules.php [L]
RewriteRule ^changelog$ ./changelog.php [L]
RewriteRule ^government/lspd/$ ./government/panel/?team=LSPD [L]
RewriteRule ^government/bcso/$ ./government/panel/?team=BCSO [L]
# 404 image
# RewriteRule \.(gif|jpe?g|png|bmp) ./assets/img/misc/404.png [NC,L]
# Ht Errors
ErrorDocument 404 /vl_web/assets/resources/hterr/index.php?error=404
ErrorDocument 403 /vl_web/assets/resources/hterr/index.php?error=403
ErrorDocument 500 /vl_web/assets/resources/hterr/index.php?error=500
ErrorDocument 503 /vl_web/assets/resources/hterr/index.php?error=503
Any idea ?
error in my .htaccess /var/www/html/vl_web/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Header is part of mod_headers, which needs to be _enabled. mod_headers is considered an "Extension", in other words:
A module with "Extension" status is not normally compiled and loaded into the server. To enable the module and its functionality, you may need to change the server build configuration files and re-compile Apache. (Source: https://httpd.apache.org/docs/current/mod/module-dict.html#Status)
Although, this will often just need "enabling" in the server config. (Requiring a webserver restart.)
php errors (that do not happen on windows so that's pretty weird): Undefined index: nom in /var/www/html/vl_web/government/panel/files/index/row2.php on line 35, referer: http://192.168.1.29/vl_web/government/
Differences in PHP versions and/or different (default) error_reporting levels could account for the differences in behaviour here. Notably, "Undefined index" messages became an E_WARNING in PHP 7 - previously this was an E_NOTICE.
'LimitInternalRecursion' errors: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://192.168.1.29/vl_web/
This is most probably caused by rewrites in your .htaccess file.
Please add the contents of your .htaccess file to you question.
Of note here is that Windows is a case-insenstive filesystem and Linux is not. The same directive might not match on Linux.
Aside:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
RewriteEngine on
</Directory>
You probably want to disable MultiViews (you are explicitly enabling it above). If you are doing much with mod_rewrite (in .htaccess) then MultiViews can often result in conflicts (depends what you are doing).
Do you really want to enable directory Indexes?
Order and Allow are Apache 2.2 directives. You are evidentally on Apache 2.4 so should be using the Require directive instead.
You do not need to enable the RewriteEngine here unless you are using it in this scope (you are not). If you are using .htaccess then this will most probably override this anyway.
In other words, this should probably be written:
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Akeneo missing files after installation process

After successfully installing the dependencies for Akeneo and the Akeneo pim-community-standard on a Debian 9 machine, I can open the login screen in the frontend on http://myhost.net/app.php
The Login process throws a 404 error on http://myhost.net/form/extensions.
This should be a JSON file (like it is on the demo installation of Akeneo), but it was not built in the installation process. Also when I manually create this file the login process goes on to the next 404:
myhost.next/localization/format/date
myhost.next/rest/security/
myhost.next/rest/user/
Which part of the installation process is supposed to build these files?
http://myhost.net/form/extensions is a call to the Symfony backend so it's not a file to generate during installation.
The 404 error seems linked to the fact that you didn't activate mod_rewrite on your apache configuration.
I add my answer because I lost a lot of time.
Solution for Digital Ocean server
Change vhost file to:
<VirtualHost your_server_ip>
RewriteEngine On
DocumentRoot "/var/www/html/web/"
<Directory /var/www/html/web>
AllowOverride None
Require all granted
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
<Directory /var/www/html/>
Options FollowSymlinks
</Directory>
<Directory /var/www/html/web/bundles>
RewriteEngine Off
</Directory>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
ErrorLog ${APACHE_LOG_DIR}/akeneo-pim_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/akeneo-pim_access.log combined
</VirtualHost>
edit your_server_ip
and load entering ip in a browser (without /web/)

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

Lamp server not showing file without extension

I am getting a weird issue i created a vhost in lamp stack. The problem is that when I open the vhost site www.domain.com the home page loads without any issue.
But when I use the nav bar to open another page I get a "404 NOT FOUND" i.e www.domain.com/about
But as soon as I put the extension of the file manually the page loads.
www.domain.com/about.php
How can I solve this issue. I am using .htaccess to hide the extension of the file.
Note:
1) All the other local file running properly i.e. I have a wordpress site that works fine (This means the mysql db is not causing the error)
2) The vhost is set properly bcus the terminal did not show any error when the vhost was enabled.
But the vhost in wamp does not give me any kind of issue in my windows 8.1 pro.
Edit :
Code in .htaccess to hide extension this works in my windows pc without any problem.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
EDIT -2
<VirtualHost *:80>
<Directory /var/www/stab-website>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
DocumentRoot "/var/www/stab-website"
ServerName stab-site.com
ServerAlias www.stab-site.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Still did not worked.
You need to enable the MultiViews options:
<VirtualHost *:80>
<Directory /var/www/htdocs>
Options Indexes FollowSymLinks MultiViews
</Directory>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/htdocs"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
</VirtualHost>
This can either be done in your httpd.conf file, in the configuration file for your virtual host or in a .htaccess file.
You should also make sure so that the mod_negotiation module is enabled. This can be done by running:
sudo a2enmod negotiation
You also might need to verify that your virtual host configuration is fine, this can be done from the terminal using:
apache2ctl -t
After this you need to restart your server:
sudo service apache2 restart
From the documentation:
The effect of MultiViews is as follows: if the server receives a
request for /some/dir/foo, if /some/dir has MultiViews enabled, and
/some/dir/foo does not exist, then the server reads the directory
looking for files named foo.*, and effectively fakes up a type map
which names all those files, assigning them the same media types and
content-encodings it would have if the client had asked for one of
them by name. It then chooses the best match to the client's
requirements.
Thanks #Cyclone for your help
This post helped me to fix this issue
https://askubuntu.com/questions/233046/how-to-give-my-user-permission-to-add-edit-files-on-local-apache-server
The post above help to run Apache server as the logged in user.
To give rights to use .htaccess --
First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/wwws
And also don't forget to add this code in the apache2.conf
<Directory /var/www/ProjectRootDirectory>
AllowOverride All
</Directory>

This script is only accessible from localhost

I have a working project with Symfony2.
One of my bundles works well by default but when I activate mod_rewrite I get
This script is only accessible from localhost
This happens only with the routes configured on this bundle, others work fine with mod_rewrite
Here is my vhost config
<VirtualHost *:80>
ServerName my_application.my_domain.net
ServerAdmin xxx#xxx.xxx
DocumentRoot "/var/www/my_application/web"
<Directory /var/www/my_application/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Where can that come from ?
Update
Example
I'm getting the error when trying to access
my_application.my_domain.net/config/list/produit
If I disable mod_rewrite I can access
my_application.my_domain.net/app.php/config/list/produit
Are you hitting app_dev.php or config.php?
By default, both of those restrict connections from anywhere but localhost and display that exact same message.
Update
After the update, I think the problem may be because you have MultiViews enabled. MultiViews can try to load config.php even if it is just referenced as config. Try removing that and see if it helps improve anything.