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>
Related
I have a very simple aim: Rewrite the URLs of my PHP app such that localhost/slim_demo/archive is interpreted as localhost/slim_demo/index.php/archive by the system but the user sees the former. EDIT: The system is behaving as if no rewriting is taking place. The latter version of the URL returns data, but the former throws a Not Found error.
I used the following .htaccess file, but it's not happening (by the way, as the second line says, uncommenting it rejects all requests, which shows that .htaccess is alive and kicking):
Options +FollowSymLinks -MultiViews -Indexes
#deny from 127.0.0.1 #Uncomment to prove that .htacess is working
RewriteEngine On
RewriteRule ^slim_demo/(.*)$ slim_demo/index.php/$1 [NC,L]
And here's the relevant section from my apache2.conf:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /media/common/htdocs>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I also did a2enmod rewrite and service apache2 restart. Frustrated, I also added this to my sites-available and did a restart:
<Directory /media/common/htdocs/>
Options +FollowSymLinks -Indexes
AllowOverride All
</Directory>
Not sure what else I need to do!
So if this .htaccess file is in the slim_demo directory, your RewriteRule never matches :
In Directory and htaccess context, the Pattern will initially be
matched against the filesystem path, after removing the prefix that
led the server to the current RewriteRule
(The pattern is in your case the ^slim_demo/(.*)$ part).
This means that when you try to get the URL localhost/slim_demo/archive the slim_demo part is removed, and your rule never can match.
So you need:
RewriteRule ^(.*)$ index.php/$1
but this will bring you in an infinite loop and a 500 error. You must trigger this rule only if the REQUEST_URI does not have the index.php.
All together becomes:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(?!/slim_demo/index\.php).*$
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
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.
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
I'm using MAMP with alias named works.
Codeigniter is at localhost/works/project/web
controllers doesn't work without index.php before them (localhost/works/project/web/index.php/auth/register)
$config['base_url'] = 'localhost/works/project/web/'; //with http://
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
(I tried all of them for uri_protocol)
I created and edit .htaccess file at /User/me/works/project/web/
I tired all the .htaccess files about this issue.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
creates error, which is:
[error] [client ::1] File does not exist: /Users/me/works/project/web/auth
it is same when I use RewriteBase /
mod_rewrite is active in phpInfo.
I couldn't find the solution.
Your RewriteBase is wrong. It should not be the relative file path for your server, it should be the relative URL path for your rewrite rules and such. More info here.
If you've ever used HTML's <base> tag, it's pretty much the same principle. If your main localhost URL is http://localhost, and your project is in the subfolder http://localhost/my-project, then you would use RewriteBase /my-project/.
If you didn't use RewriteBase, and your project is in a subfolder, you'd have to add the subfolder to every one of your URLs and rewrites, like this:
RewriteRule ^(.*)$ /my-project/index.php/$1 [L]
Food for thought:
Start your .htaccess files as simple as possible. The more you throw at it right away, the more that can go wrong, and the harder it is to debug. Especially if you're a noob to .htaccess files. Don't blindly copy and paste -- figure out what things actually do.
The system folder access part is redundant now -- the system folder has its own .htaccess to restrict requests, just like the application folder.
1.Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.use this in .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and enable rewrite mode using below command
a2enmod rewrite
and Edit the file /etc/apache2/sites-enabled/000-default
change the AllowOverride None to AllowOverride All.
and finally Restart your server
You certainly don't have mod_rewrite on or you did not install it with MAMP
Open your httpd config file and change
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
To
AllowOverride All
uncomment this line:
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Also make some changes to users here: /etc/apache2/users/username.conf
LoadModule php5_module libexec/apache2/libphp5.so
DocumentRoot "/Users/username/where/ever/you/like"
<Directory "/Users/username/where/ever/you/like">
Options Indexes MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Get more info here http://adam.merrifield.ca/2010/08/09/apache-mod_rewrite-php-and-os-x-10-6-snow-leopard/
Restart MAMP
To find out if mod_rewrite is on, follow this answer in Stackoverflow:
How to check if mod_rewrite is enabled in php?
Just to be sure your .htaccess is not the issue, could you try this one. It's been tested:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Users/me/works/project/web/
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads|css|images|js)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Access to certain folders are granted above and the rewritebase has a trailing slash.
Make sure you have any other nested .htaccess overriding this very one.
I fixed the problem by instead of using .htacces, I write them to httpd.conf.
I checked the AllowOverride is All but I'm not sure why .htaccess isn't working. Because of I lost too much time with this issue, I'm going to use this way.
Thanks for the answers.
Use AllowOverride All on your vhost:
<Directory "/path/to/your/site">
....
AllowOverride All
</Directory>
Open your httpd config file
LoadModule rewrite_module modules/mod_rewrite.so then AllowOverride All
<Directory "C:/xampp/htdocs"> //example for xampp
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I have installed codeigniter in a url like the format: http://11.12.34.45/~project/
I tried different suggestions and finally this following url provided the solution:
https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
You need to change two files of Apache,
httpd.conf
httpd-vhosts.conf
change this in httpd.conf
<Files ".ht*">
Require all denied
</Files>
to,
<Files ".ht*">
Require all granted
</Files>
and add below code in httpd-vhosts.conf,
<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
</Directory>
</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 /