Laravel Setup - "AllowOverride all" is causing a 403 - .htaccess

Trying to get a test Laravel project running on the server. If I navigate to the sites URL I am presented with the Laravel welcome screen but none of the routes are working.
To fix this I have changed the .htaccess file as specified by the laravel website.
The problem is in order for the .htaccess to be utilised I have to "AllowOverride all" in my virtualhost file which is causing a 403 to be presented instead of the welcome page.
The error I'm getting is:
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request
Just for testing purposes I have given the entire laravel folder 777 to make sure there isn't a a file permission issue.
Any help would be greatly appreciated. Thanks
Content of my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Content of my VirtaulHosts:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/testProject1/public
DirectoryIndex index.php
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<Directory> must refer to an absolute path, whereas <Location> can refer to a path relative to the document root.
As such, change:
<Directory />
to:
<Directory /var/www/testProject1/public>
And don't forget to reboot Apache.

Related

laravel virtualhost 404 error

I have apache2 on my ubuntu server.
There is my /etc/apache2/sites-available/laravel.conf
<VirtualHost *:80>
ServerName http://laravel.mysite.com/
DocumentRoot "/var/www/laravel/public"
<Directory "/var/www/laravel/public">
AllowOverride all
Order allow,deny
 Allow from all
</Directory>
</VirtualHost>
and I have open the apache's mod_rewrite function.
There is my /var/www/laravel/app/routes.php
<?php
Route::get('/', function()
{
return View::make('home/index');
});
Route::get('/hehe', function()
{
return "hehe';
});
There is my /var/www/laravel/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and now, I can visit the http://laravel.mysite.com, but when I visit the http://laravel.mysite.com/hehe, it gives the 404 error. Is there anything I config wrong?
Although the question is very old, for anyone still interested (as was me, but managed to solve the problem), I created a checklist to go through if Laravel routes throw a 404 or 403 error.
I assume that Laravel's originally installed public/.htaccess file is unmodified.
Be sure to insert the <Directory> section into the virtual host's apache config file with the proper path.
Be sure to have AllowOverride All, and not None in the <Directory> section to allow routes (avoiding 404 error).
Be sure to have Require all granted, and not denied in the <Directory> section to give permission visitors to see the site (avoiding 403 error).
It may also be necessary to include Options FollowSymLinks in the <Directory> section if you use symlinks in your app.
Be sure to have the rewrite module enabled in apache: $ sudo a2enmod rewrite
And don't forget to restart the apache server for the changes to take effect.
The only thing i do is to devise the apache2.conf, add this:
<Directory /var/www/laravel/public>
Options FollowSymLinks
AllowOverride All
</Directory>

Laravel 4 routing not working due to .htaccess file?

I'm writing my steps and findings here so you can see what I've tried and what results I got. Any advice would be welcomed. I followed the comments in this answer.
I'm running Laravel 4, using XAMMP version 1.8.2 with PHP 5.4.19 and Apache 2.4.4 on a Windows 7 machine and I'm simply still trying to get a local instance up and running.
In my case: http://localhost/sos/sos_public/ is my main screen and that works, but when I try to get to http://localhost/sos/sos_public/signup I get this error: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException which has been talked about a lot on the net, and then I found GaryJ stating that it might be an .htaccess issue, so I did what he suggested.
My /app/routes.php file looks like this (I've tried this with a / in front of signup too):
Route::get('signup', function()
{
return 'hello!';
});
Route::get('/', function()
{
return View::make('hello');
});
First:
Just for a laugh, see if /index.php/hello works. If so, then it's a .htaccess problem.
http://localhost/sos/sos_public/index.php/signup worked perfectly fine. So it's an .htaccess problem.
My .htaccess file looked like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And:
if you're running Apache 2.4, note the changes since previous
versions, regarding Require all granted and AllowOverride all within a
<Directory />...</Directory> block on your virtual host.
I added this in my httpd.conf file as suggested by Dalton Gore - got the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException error (changed this directory path to /SOS/sos_public and C:/xammp/htdocs/SOS/sos_public/ and C:/xammp/htdocs/SOS/sos_public - same results):
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory /SOS/sos_public>
AllowOverride all
Require all granted
</Directory>
Next:
Check if anything in .htaccess is working
I added dsjkdsfghk to my .htaccess file and immediately got an error, so I know my .htaccess file is being used.
Then:
Try removing the IfModule conditional. As you've got access to the
host / vhost, you can soon enable that module if it's not - so it
doesn't need be checked on every request. Equally, try moving it out
of .htaccess, and into a <Directory />...</Directory> block in your
vhost - if you've got nothing else in your .htaccess it can then be
deleted as well.
Having an empty .htaccess file caused a 404 error in my browser for http://localhost/sos/sos_public/signup (http://localhost/sos/sos_public/ still worked).
Removing the .htaccess file from C:\xampp\htdocs\SOS\sos_public\ had the same results.
Then:
Try: <VirtualHost *:80> DocumentRoot
"/Users/amiterandole/Sites/laravelbackbone/public" ServerName
laravelbackbone.dev <Directory /> AllowOverride all Require all
granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^
index.php [L] </IfModule> </VirtualHost>
I did that and just like Amit,
I emptied out my htaccess file and tried the above and now nothing
seems to work.
Except where his laravelbackbone.dev pointed to his Sites folder root, I just got an Error 400 - Bad request on both http://localhost/sos/sos_public/ and http://localhost/sos/sos_public/signup when I ran them in my browser.
My httpd-vhosts.conf file looked like this:
<VirtualHost *:80>
DocumentRoot "C:/xammp/htdocs/SOS/sos_public"
ServerName sos.dev
<Directory />
AllowOverride all
Require all granted
</Directory>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</VirtualHost>
and in my .hosts file I obviously had:
127.0.0.1 sos.dev
Lastly:
You've definitely got the conf/extra/httpd-vhosts.conf file be
included (uncommented) within the main httpd.conf?
I have this uncommented - yes.
Another link I tried but to no avail: https://stackoverflow.com/a/17778222/956975 and http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working
What should I change where?
What am I missing?
Your ServerName is
sos.dev
And apache take this in consideration, you you must access your routes using:
http://sos.dev/
And NOT
http://localhost/
It might be the error of not enabling rewrite Engine in apache2
In linux,
sudo a2enmod rewrite
sudo systemctl restart apache2
In windows,
You should find httpd.conf file if it's not available in your apache look for apache2.conf file is another name for httpd.conf and enable the rewrite module for more info or here see how to do above-said procedure in this link
Lost httpd.conf file located apache

How to get .htaccess files working with Apache VirtualHost

My problem is that my .htaccess file on my local server is not being read. The settings in the VirtualHost file seem to always take precedence.
I have tried the following:
Enabled mod_rewrite
Changed the AllowOverride to All but this causes a HTTP Error 500 Internal server error. I have tried it with various options but it always causes a 500 error.
I am using a VirtualHost file on Ubuntu which looks like the following:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /web/website
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /web/website>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
In my .htaccess file under /web/website I have the following rules (which are not being read):
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit
RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA]
ErrorDocument 404 /404
ErrorDocument 401 /401
One thing I tried which did work was appending these rules directly into the VirtualHost file, but I would like my .htaccess file to work! Is that such a big ask? :(
Edit: So I looked in my apache error.log and it says Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration referring to my .htaccess file. There doesn't seem to be a module called Action which I can enable. Any ideas?
Edit 2: I noticed that my httpd.conf file is blank. Should this matter since I am using VirtualHost files?
After looking at my apache error.log I realised I just had to enable the Apache actions module:
sudo a2enmod actions
And no more 500 Internal Server Errors!
Hope this helps somebody down the line :)
You miss the RewriteBase / directive
Add it after the RewriteEngine directive :
RewriteEngine On
RewriteBase /

.htaccess: RewriteEngine not allowed here

I uploaded the .htaccess to the server and received an Error 500 (Internal Server Error).
And in the error log I had the following error:
.../.htaccess: RewriteEngine not allowed here
But mod_rewrite.so is enabled.
So, do I need to change
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
to
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
in the /etc/httpd/conf/httpd.conf file?
Or could it be something else? The .htaccess file should be okay, because it works perfectly fine on my localhost. I just don't want to screw anything up.
Here's part of my .htaccess file:
Options All -Indexes
Options +FollowSymLinks
RewriteEngine On
minimum configuration for your .htaccess to work:
AllowOverride FileInfo Options
allowing all configuration will work as well:
AllowOverride All
Let's say your DOCUMENT_ROOT is /home/foo/web then have this config in your httpd.conf file:
<Directory "/home/foo/web">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This should take care of RewriteEngine is not allowed error you're getting.
Just an idea, this happened to me, and I've lost a lot of time trying to solve it.
If you have a directory like d:/web/my-sites/some-site/
And you place the .htaccess on d:/web/my-sites/some-site/.htaccess (where it supposed to be).
If you have ANY .htaccess files before this directory, Apache reads that files, and blocks the execution of the entire path, producing an internal server error.
I.E.: You have d:/web/my-sites/.htaccess
In httpd version 2.4 (2.4.3 and 2.4.4), take a look at /etc/httpd/conf.d/wordpress.conf
There is one entry for:
....
Change:
"AllowOverride Options"
to
"AllowOverride All"
in wordpress.conf also in addition to changing httpd.conf. Restart the http server before the changes will take effect.
Also, just make sure you are editing the correct config file. I had created a file under /etc/apache2/users/USERNAME.conf but was editing /etc/apache2/httpd.conf.
Removing the USERNAME.conf file worked.
Try to change username.conf file on Mac under /etc/apache2/users/username.conf to
<Directory "/Users/akyoo/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
My .htaccess file looks like this
#Allow from all
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
This works fine for me.
Solution for Ubuntu users
I was getting this type of error from the Google Cloud instance after checking the logs from the /var/log/apache2/error.log
.htaccess: RewriteEngine not allowed here
To get rid of the above error & 500 Internal Server Error, follow these simple steps
sudo nano /etc/apache2/apache2.conf
Then add these snippets of lines
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After you’ve made that change, make sure to restart the server:
sudo service apache2 restart
This worked for me in getting rid of 500 Internal Server Error hosted on Google Cloud instance
you could use something like this in your .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|html|test)
RewriteRule ^(.*)$ /index.php/$1 [L]
this code simply means, that anything not pointing to index.php or html or test should be directed to index.php!
Hope this is helpful!

Mod-Rewrite loading files behind the DocumentRoot

I'm using .htaccess and mod_rewrite to point to files that reside behind the DocumentRoot. My folder structure looks like this:
home/
webroot/
other_files/
I have a .htaccess file in webroot with the following content:
RewriteEngine on
RewriteRule ^(.*)$ /home/other_files/$1
If I try to access http://example.com/file.html I receive the following error:
The requested URL /home/other_files/file.html was not found on this server.
Is it even possible to load files that are behind the DocumentRoot? If so, can someone point me in the right direction?
I believe you need to add a section with
<Directory "/home/other_files">
(options)
</Directory>
to your server configuration before apache will be able to serve anything from it. For an example, my DocumentRoot is /var/www but there is this section in the default available site:
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
You could then rewrite a URL to go to /doc/ and the server would know where to get the files from.
Just so you know why that rule doesn't work:
The reason that it isn't able to rewrite to /home/other_files/file.html is that mod_rewrite is parsing the path as /home/webroot/home/other_files/file.html since from mod_rewrite's point of view the preceding slash is equivalent to your document root of /home/webroot.
Ryan Ahearn's suggestion is a decent one, and is likely the route you want to go.
The credit goes to Ryan Aheam, but I'm going to spell it out. I'm a beginner and even with Ryan's answer I had to experiment with a few things to get the syntax right.
I wanted my DocumentRoot to be my cakephp directory. But then I had a Mantis Bug tracker that was just regular PHP and so not in the cakephp directory. The the files below I have the following working.
http://www.example.com : served by /var/www/cakephp
http://www.example.com/mantisbt : served by /var/www/html/mantisbt
File /etc/httpd/conf/httpd.conf
Alias /mantisbt/ "/var/www/html/mantisbt/"
<Directory "/var/www/html/">
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerAdmin me#my_email.com
DocumentRoot /var/www/cakephp
ServerName my_website.com
<Directory /var/www/cakephp/>
AllowOverride All
</Directory>
</VirtualHost>
File /var/www/cakephp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^mantisbt/?$ /mantisbt/ [NC,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

Resources