laravel5.1 laravel in subfolder (routes not working) results in 404 apache error - apache

My current setup on my production server is like the following:
there are two folders in
var/www/html
These two folders are named:
xyz
doge
Now I would like to place all requests to IP/doge into the doge folder.
This seems to work, but only the index page is working. Using the already created routes like for example:
ip/doge/login
will result in a 404 error page of apache.
Here's my apache config:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/xyz/public
Alias "/doge" "/var/www/html/doge/public"
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html/xyz/public/>
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Any idea where's my fault? I haven't changed the .htaccess in the public folder of each laravel project. This .htaccess looks like:
<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>

Related

Apache ignores .htaccess file

I have a debian apache server. For some reason apache ignores my .htacces file. Any ideas why this is happening?
Here is my /etc/apache2/sites-available/default file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride none
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
I have also enabled apache rewrite mod.
Panama Jack thank you so much,
Based on your answer i find out the solution i was looking for. I added at the top of my .htaccess this line
Options +FollowSymLinks -MultiViews
that i found here
RewriteEngine On .htaccess not working
Thanks so much again!

Apache ErrorDocument issue

i am trying to make my own 403 page but my apache doesn work correct.
I use
ErrorDocument 403
but it shows the same. This is my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
Here is my host settings:
<VirtualHost 127.0.1.15:80>
ServerAdmin webmaster#localhost
ServerName turik.loc
ServerAlias *.turik.loc
DocumentRoot /home/golars/proj/turik/
<Directory />
Options FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /home/golars/proj/turik/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/t4base_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
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>
To 403 error i am going to turik.loc/img/hotels/ -where i dont have permissions to read&write. I would be graceful for a help.

Remove index.php from Laravel 4 URL and Rewrite www to non-www

I have tried several ways to remove index.php from my URL (http://www.example.com/index.php/login), as well as redirecting www to the non-www URL.
Here is my default Apache VirtualHost file:
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now I have added the following in to this file:
Redirect 301 / http://example.com
But this has not worked, I just get a redirect loop message. I also have the following .htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To which I've added:
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
But this does not work either.
The other issue is that for all of my routes I have to include index.php, like http://example.com/index.php/test
It's as if my .htaccess file is being ignored.
The server is a DigitalOcean Droplet running Ubuntu 13.04 x64. It has PHP 5.4.9 and Apache 2.2.22.
Any help would be very much appreciated. Thanks.
Thanks to anlutro in #laravel IRC chat, he pointed out that mod_rewrite may not be enabled. Usually this is on by default in all the servers I've ever worked with so it didn't click, as I've never had to enable it but on this DigitalOcean server, it wasn't.
I used:
a2enmod rewrite to enable it and then I restarted apache. All is good.
Cheers

htaccess vhost codeigniter index.php

I have read a lot of topic with the same problem but i do not find the solution... please help me. I have a lamp into ubuntu server. My document root is /home/utente/ into this dir I have another dir (turni) with a codeigniter web app. The web app works fine with the "index.php" into the url, but I want to eliminate it. I have this configuration:
config.php into codeigniter:
$config['index_page'] = '';
.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
/etc/apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/utente
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/utente/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
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>
When i open a link of the web app with without eh "index.php" into the url, the server o me this error: The requested URL /turni/auth/login was not found on this server.
Why??? If i put the index.php like /turni/index.php/auth/login all works fine....
Thanks for help and sorry for my english :D
Add .htaccess to your server root directory and change the rewrite base to
RewriteBase /turni
assuming your codeigniter is present in /var/www/turni

Redirect non-existent dynamic virtual host folders with Apache

Is it possible to redirect to a certain URL if the directory for the virtual host doesn't exist? I have a VirtualHost setup below that lets me host a domain just by creating the folder, and pointing DNS to my server.
Here is my configuration for the VirtualHost
<VirtualHost *:80>
ServerAdmin webmaster#localhost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/ [R=301,L]
VirtualDocumentRoot /var/www/%0
<Directory /var/www/%0>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
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>
</VirtualHost>
You can manage it using rewriting rules.
Just after you rewriting rule to skip www :
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteCond /var/www/%1 !-d
# I think just /var/www/%{HTTP_HOST} works :|
RewriteRule .* http://example.com/nonexistant.php/$0 [L,R]