I created web app with Laravel, which I tested on laravel server ( php artisan serve ) and now I want to put it on LAMP so I can test it further, but something is wrong.
When I visit localhost/public/ I get my home page but when I click on any link inside my app I get Not found error. On the other side, when I manually input localhost/public/index.php/someURL then I get the linked page.
Can someone tell me how to fix this?
This is my .htaccess file inside public directory:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
This is the content of apache2 conf file ( /etc/apache2/sites-available/000-default.conf ) :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory "/var/www/html">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And I enabled mod_rewrite with this command: sudo a2enmod rewrite
I'm using Ubuntu 14.04.
UPDATE:
App is placed inside /var/www/html/
Go to /etc/apache2/apache2.conf file and make sure it looks like this:
<Directory /var/www/html>
Options Indexes FollowSymLinks
Allowoverride All
Require All Granted
</Directory>
You can locate it right after
<Directory /usr/share>
....
</Directory>
Perform mod_rewrite and restart apache and it should work!
This is how I fixed it. I created another .htaccess file and placed it in root directory /www/html/:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Information taken from here: http://driesvints.com/blog/laravel-4-on-a-shared-host
Related
I have deployed an application to an apache server and it works fine, well only the homepage. As soon as I try to go to a route I get the Not found error in my request log I see GET /users 404
My virtual host file:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
The .htaccess file is just the default laravel one with apache being able to access and read it.
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I'm a bit lost since I don't get any errors in my log and I have no idea what is going on.
what's about this:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
Probably you don't wanna hear this, but switching to Nginx will solve a lot of these problems , and your site will run faster. That's why Laravel Valet uses Nginx.
I set up a local Laravel server for developement and push changes through Git to my production server.
I made a new Laravel project that i pused ok. Then i added php artisan make:auth on my local server and pushed to production but get 404 cant find login (or register). After some work I found out that:
www.mySite.com/login
can not be found but if I write
www.mySite.com/index.php/login it works.
So now I think I have to modify my htaccess to ignore the index.php but I cant get it to work. I tried some suggestions but none seems to work and I don't have a clue why it is not working.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase Test/public/
* RewriteCond %{THE_REQUEST} /index\.php [NC]
* RewriteRule ^(.*?)index\.php$ /$1 [L,R=302, NC, NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
The two lines marked with * I tried to add after reading a suggestion here on Stack Overflow (cant find the link now). I also tried
htaccess remove index.php from url
this suggestion.
Any ideas? Thanks.
Edit:
My sites-enabled/000-default.conf looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =nfoscan.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
and my 000-default-le-ssl.conf Looks like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mysite.com
</VirtualHost>
</IfModule>
I removed the comments in configs..
I tried to add
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
to my 000-default-le-ssl.conf but it resulted in internal server error..
First check if your apache has enabled mod_rewrite you can do it easily by
typing
apache2 -M
or even simpler:
a2enmod rewrite
if you had enabled it already you will receive message:
"Module rewrite already enabled"
If you haven't then you will receive message:
"Enabling module rewrite". You will have to restart apache.
Check if you have in you htaccess line (AllowOverride All)
<Directory /var/www/html/project/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Ok so I fixed it. There was some problem in my .htaccess file. I started with removing the .htaccess file in /Test/public and then I didnt get internal server error when messing with in 000-Default-le-ssl.conf file anymore. Then I just copied in another .htaccess file in the directory and it all worked as it should :O
Thanks to all who tried to help me!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Posting the working .htaccess file if anyone ever have this problem again :)
I want use mod_rewrite but seems that is not working, I activated it and I setup in my .htaccess but nothing seems to work.
I want to NOT display index.php in my URL :
instead of
localhost/index.php/admin/login
I want to display
localhost/admin/login
I am under Ubuntu
Here is what my phpinfo() says :
This is my .htaccess :
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
#RewriteBase /virtualpost
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:/virtualpost]
#RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!localhost).)*$
RewriteRule . - [E=REWRITEBASE:/]
# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(system\/virtualpost\/cache|system\/codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is my /etc/apache2/sites-available/000-default.conf :
<VirtualHost *:80>
SetEnv MYSQL_DB_HOST localhost
SetEnv MYSQL_USER root
SetEnv MYSQL_PASSWORD spaces
SetEnv MYSQL_DB_NAME clevvermail
<Directory ...>
AllowOverride All
</Directory>
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>
I figured out that I had to config the apache2.conf file /etc/apache2/apache2.conf and change
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None <<-- Rewriting desactivated
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All <<--Activate rewriting
Require all granted
</Directory>
I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.
Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instances production,staging and dev using the following links
serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev
I found another SO question which seems to be doing the same thing. But when I tried to do the same thing I get the following error
Forbidden
You don't have permission to access /dev on this server.
Here is what I have done so far. In my httpd-vhosts.conf file I added the following VirtualHost
<VirtualHost *:8080>
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
DocumentRoot "C:\www\dev\public"
ServerName serv1.example.com
ServerAlias /dev
<Directory "C:\www\dev">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Then I changed c:\www\dev\public\.htaccess the code to the following
<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>
What did I do wrong here? how can I access each instance using the same domain?
Try This one, in your Apache configure file /etc/apache2/sites-available
<VirtualHost *:8080>
ServerName serv1.example.com
ServerAlias serv1.example.com
DocumentRoot "C:/www/dev/public"
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "C:/www/dev/public">
Options All
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
# Log file locations
LogLevel warn
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
And in your c:\www\dev\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]
I hope this would work. for more information follow these links.Multiple laravelsites on single apache server , multiple web sites in single laravel installation
Im using laravel 4.
I have a view nest.blade.php and the corresponding controller NestController.php:
Controller content:
class NestController extends BaseController {
public function showView()
{
return View::make('nest');
}
}
Route:
Route::get('/nest', 'NestController#showView');
When I go to url/nest it doesnt work.
When I go to url/index.php/nest it does work.
Obviously I just want it to be /nest without the index.php.
How can i resolve this?
My 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>
Pretty URLs
The framework ships with a public/.htaccess file that is used to allow
URLs without index.php. If you use Apache to serve your Laravel
application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your
Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
For more related help, check this answer.
I enabled the mod_rewrite module in the Apache HTTP server, restarted Apache service and tested again and it WORKED!!!
Below is the code i used to enable mode_rewrite;
1) Un-Hash this line in Apache/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
2) Create a new configuration for "sample-project" without modifying the default configuration in the httpd.conf file
Directory "C:/Apache24/htdocs/sample-project">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Directory>
Be Alert! If it is not working even after enabling rewrite module. You need to change the line "AllowOverride None" to "AllowOverride All" in httpd.conf.
As #The Alpha alerted, Laravel don't need to be configured for this purpose.
When you change the line AllowOverride None to AllowOverride All in httpd.conf be sure that you do it inside <directory ...> that contains valid path.
Example
<Directory "/var/www/html"> #check path
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
For some reasons the answers above are not working for me, so here is the only one that worked for me.
I am using ubuntu 18.04 amd64 as my development server environment.
So I modified apache.conf file located at/etc/apache2
From:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted
To:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted
And Also From:
<Directory /usr/share> AllowOverride None Require all granted
To
<Directory /usr/share> AllowOverride All Require all granted
After that, you need to restart apache using sudo service apapche2 restart command in the terminal
Now I can access the page without using index.php in the URL
Credit goes to: joshymatheww # Laracasts servers discussion channel on
Aug 5, 2017
Login to the terminal
sudo nano /etc/apache2/apache2.conf
After line
<Directory /var/www/>
.
.
.
</Directory>
and paste below code
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
Now Ctrl+O and then Ctrl+M and then Ctrl+x
Now restart apache server
sudo service apache2 restart
First of All you need to set AllowOverride All in /etc/apache2/apache2.conf. Find the following block:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
DirectoryIndex index.php
Require all granted
</Directory>
then you need to modify /etc/apache2/mods-available/dir.conf and move index.php first :
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
AND DO NOT FORGET: Run a2enmode
sudo a2enmod rewrite
and then
sudo service apache2 restart
This way you apply it for all your laravel projects (inside /var/www/ folder).
set this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
Try the following .htaccess. I never had any trouble with that on a server or localhost environment.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>