Apache2 - Error: 403 after installation of RewriteEngine - apache

I have to following problem. After installing RewriteEngine on my Apache server by sudo a2enmode rewrite && service-apache restart I am getting a 403 Permission Error, when trying to access the Website. The error log reads:
[Mon Aug 03 16:47:04.772033 2015] [authz_core:error] [pid 27107] [client ::1:41610] AH01630: client denied by server configuration: /home/lenxn/Venuzle/vvm/public/
The access log:
::1 - - [03/Aug/2015:17:08:11 +0200] "GET / HTTP/1.1" 403 2267 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.8.0"
The apache2.conf remained unaffected from the installation and the .htaccess in my source root directory looks like:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
What is the problem here? I have been able to access the server previous to the installation. Have there been any files created or alternated, which overrule my previous permission settings?

I finally fixed it by altering the section
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
from the apache2.conf to
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory> .

Related

Symlink to /project/current/web work but not to /project/current/web/app.php (Apache / Ubuntu / Symfony2)

Symlink to /var/www/myproject/current/web/ is working but is listing the web directory (not good).
Symlink to /var/www/myproject/current/web/app.php isn't working and give me this error : The requested URL / was not found on this server.
no logs in /var/log/apache2/error.log and this line in /var/log/apache2/access.log - 404 error
ip - - [17/Mar/2016:06:21:15 -0400] "GET / HTTP/1.1" 404 493 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"
Here are the set up :
Symfony2 + Capisfony + Apache + Ubuntu 14.04
Here is my apache2.conf
<Directory />
Options FollowSymLinks
AllowOverride all
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Here is the .htaccess in /var/www/myproject/current/web
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
And here is how I make the sym link
rm -rf /var/www/html
ln -s /var/www/myproject/current/web/app.php /var/www/html
service apache2 restart
==> 404
rm -rf /var/www/html
ln -s /var/www/myproject/web/app.php /var/www/html
service apache2 restart
=> You don't have permission to access / on this server.
[Thu Mar 17 06:44:53.385300 2016] [core:error] [pid 19767] [client 88.14.213.213:51484] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html
I suggest you to work with the vhost of apache instead :
It's from the symfony cookbook : http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
You let apache manage the document root, and you add app_dev.php to url to use the dev environment, it's convenient if you have another env, like staging, on to test the prod env sometimes
To prevent listing of files add :
Options -Indexes
to your directory section of the vhost
The answer is :
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
The AllowOverride None was blocking the .htaccess
Thanks for helping.

Receiving 404 error after setting up mod_rewrite

I'm developing a website locally on Ubuntu + Apache + Virtual hosts, but am having some problems customising urls with mod_rewite. First I was getting an internal server error, but then I found I had to turn mod_rewite on so I found this tutorial...
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite
...swapping out their path names for my own.
My virtual hosts sites-available conf file codecourse.dev.conf...
<VirtualHost *:80>
ServerName codecourse.dev
ServerAlias www.codecourse.dev
ServerAdmin admin#codecourse.dev
DocumentRoot /var/www/codecourse.dev/public_html
<Directory /var/www/codecourse.dev/public_html >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
My .htaccess file which lives inside the public folder...
Options -MultiViews
RewriteEngine On
RewriteBase /var/www/codecourse.dev/public_html/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
My apache access log when trying to pass the url: codecourse.dev/public/home/index/Leon
192.168.0.105 - - [20/Nov/2015:08:30:32 +0200] "GET /public/home/index/Leon HTTP/1.1" 404 544 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
Note: This access error only appears when passing a custom url. Otherwise accessing codecourse.dev/public works as expected.
Can anyone see what I'm doing wrong here?
Notice, you have set your DocumentRoot in Virtualhost, remove RewriteBase or set it to /public.
Btw, for checking yourself you can add R flag to your RewriteRule and see, what url you get.

Centos Apache Mod Vhosts Alias returns error 500

I am not able to convert this (working) virtual host configuration
<VirtualHost *:80>
ServerName test.1.2.3.4.xip.io
ServerAlias *.test.1.2.3.4.xip.io
DocumentRoot "/var/www/vhosts/test/public"
<Directory "/var/www/vhosts/test/public">
AllowOverride All
</Directory>
</VirtualHost>
Into this more versatile one (using mod_vhosts_alias)
<VirtualHost *:80>
UseCanonicalName Off
ServerAlias *.1.2.3.4.xip.io
VirtualDocumentRoot "/var/www/vhosts/%1/public"
<Directory "/var/www/vhosts/*/public">
AllowOverride All
</Directory>
</VirtualHost>
I'm on Server version: Apache/2.2.15 (Unix) CentOS release 6.6 (Final) AllowOverride is set to None on / in httpd.conf
I get
[Thu Aug 06 14:37:37 2015] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.5.25 configured -- resuming normal operations
[Thu Aug 06 14:37:39 2015] [error] [client 1.2.3.4] 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.
Even setting that LogLevel I can't get more info.
This is also my .htaccess just in case (it's Laravel default one)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Thanks

.htaccess file not found

I got my website done by my friend it is up and running in the public server. I tried to run the same website on my internal server. But apache says file not found. I figured out that the problem is in .htaccess file. This is my file
AddType text/x-component .htc
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
and in my apache conf file I set
<VirtualHost *:80>
DocumentRoot /srv/www/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /srv/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
<Directory /srv/www/companies/test1/>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order Allow,Deny
Deny from all
Allow from 192.168.43.0/255.255.255.0 192.168.42.0/255.255.255.0
</Directory>
</Virtualhost>
error log says
[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.8] File does not exist:/srv/www/cms
[Fri Apr 11 16:57:33 2014] [error] [client 192.168.43.19] File does not exist:/srv/www/products, referer: http://192.168.43.8/companies/
I guess htaccess is lokking for index.php in /srv/www/ folder instead of /srv/www/companies/test1/ folder. Any suggestion how to direct htaccess in correct location?
Assuming you have a cms and product directory in /srv/www/companies/test1/ instead of /src/www/ you could fix the issue by changing your DocumentRoot /srv/www/ to DocumentRoot /srv/www/companies/test1/ and restarting apache.
Generally though, you'd want to set up a custom VirtualHost for each site you are planning on serving and leave the default <VirtualHost *:80> set to whatever should be served by default when you visit your IP address.
See VirtualHost Examples for some examples of common setups.
the .htaccess file is located in the root folder of your instalation and by default is hidden.
If you are using FileZilla:
Start FileZilla then select the "Server" menu at the top
Select "Force showing Hidden Files"

Rewrite rule for relative path?

The error in browser I get is:
The requested URL /home/user/public_html/some_folder was not found on this server.
And the apache log is:
[Sat Aug 17 20:57:57 2013] [error] [client ] File does not exist: /var/www/html/home
So naturally I think, I'll try RewriteBase /../../../home/user/public_html/, but that gives me:
[Sat Aug 17 20:59:22 2013] [error] [client ] Invalid URI in request GET /~user/ HTTP/1.1
How do I get around this?
The .htaccess is simple:
RewriteEngine On
RewriteBase /../../../home/user/public_html/
RewriteRule index.php some_folder/index.html [L]
You could use a symlink.
cd /var
cp /var/www /var/backup_www
rm -rf /var/www
ln -s /home/user/public_html/ www
And enable following symlinks in your httpd.conf.
<Directory /var/www>
Options FollowSymLinks
</Directory>
<Directory /home/user/public_html>
Options -FollowSymLinks
</Directory>
Alternatively, just change the DocumentRoot for the server/vhost.