Mod rewrite isn't working on Laravel at Apache sublocation - php

I want to have a Wordpress and a Laravel under the same domain, so I can keep Wordpress and Laravel session always up and have Single Sign On between both. This objetive was achieved, but now I want to move laravel to another folder for security and define an Apache Alias with a sublocation. This is working too.
But the friendly URLs in laravel stoped to working. I think that I need make some change on .htaccess. I leave how I have my Apache2 config right now.
<VirtualHost *:80>
ServerName einflamatoria.inventeddomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/einflamatoria-foro-wp
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /educaforo-master /var/www/educaforo-master/public
<Location /educaforo-master>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require all granted
</Location>
</VirtualHost>
And Laravel .htaccess right now is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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?$1 [L,QSA]
</IfModule>
With this configuration if I want to go to
einflamatoria.inventeddomain.com/educaforo-master/forums gives me a 404
but if I go to einflamatoria.inventeddomain.com/educaforo-master/index.php/forums works fine, but I need that it works without index.php.

Related

Requested URL not found - Laravel 6

I am trying to upload a my project to the server.the first page is working properly and when i go for another page am getting error like The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at 142.93.209.171 Port 80. i think the problem is at .htaccess file,here is my .htaccess file placed in the public directory
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Here is my app_url placed in .env file
APP_URL=http://142.**.***.***/
Here is the virtual host configuration
DocumentRoot /var/www/studio/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/studio/public>
Options +Indexes +Includes +FollowSymLinks +Multiviews
AllowOverride All
Require all granted
</Directory>
i tried a lot but always getting 404 error

Unable to browse to anything other than the main URL on a new Laravel Apache2 setup. ERROR: The requested URL was not found on this server

I've set up a new Laravel site with an Apache2 webserver and have mimicked the setup of a similar working site, on the same server, but every time i browse to a URL which is example.com/anything it gives me a 404 page not found error. The main site url works, but no pages are accessible.
Eg:
example.com {{ This works fine }}
example.com/home {{ Errors with page cannot be found }}
example.com/anything-i-put-here {{ Errors with page cannot be found }}
The site works fine on other servers and locally, so im certain its not the Laravel site itself thats broken. Another laravel site on the same server with basically identical setup (as far as i can see) works fine, so I know the server itself is set up correctly and is serving other sites.
I'm fairly new to apache2 virtual server setup, so im pretty sure i've just not configured this correctly. I've been trawling through the internet and have read so so many posts reccomending people to set up the apache2.conf and the .htaccess files basically exactly the same as i have them, so im at a bit of a loss. Has anyone got any suggestions?
apache config file (symlinked in sites-enabled):
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect 301 / https://example.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com/public_html/public
ServerName example.com
<Directory /var/www/example.com/public_html/public>
Options -Indexes +FollowSymlinks +MultiViews
AllowOverride All
Require all granted
# SSLRequireSSL
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/www/example.com/fpm/php7.2-example.sock|fcgi://localhost/"
</FilesMatch>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile path/to/key.pem
SSLCertificateKeyFile path/to/key.pem
</VirtualHost>
.htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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]
</IfModule>
and yes, modrewrite is enabled
Use the following code in your .htaccess after RewriteEngine On
RewriteBase /
So your .htaccess should look like the following:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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]
</IfModule>

Laravel vhosts setup in xampp is working for only first page

I am working with laravel project. It works fine with php artisan. When I setup vhosts it's working only index page(Welcome page) but when I click on login,signup or any other pages it's not working. It shows page not found.
My httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/my_laravel/public"
ServerName laravel.dev
ServerAlias laravel.dev
ErrorLog "logs/laravel.log"
CustomLog "logs/custom.laravel.log" combined
<Directory "C:/xampp/htdocs/my_laravel/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
And my hosts file
127.0.0.1 laravel.dev
.htaccess file inside public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
</IfModule>
You have to define URL rewrite in the public/.htaccess File.
Check if you have the correct settings there.
The Laravel default File looks like this:
<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]
Just backup your .htaccess and try to copy paste this to your htaccess file and check if it works. If you use Laravels Authorization you also have to add this
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Maybe you also have to turn on the Modules mod_rewrite.c and mod_negotiation.c if they arent already.
You can do this by search and uncomment the line for the desired module in apache\conf\httpd.conf
If you want to customize your .htaccess for what ever reason there are many ressources available on the web.

Laravel Routes not working 404 not found

I change my pc and install lamp on Windows 10 WSL.The main index works / but the routes is not. Here is my virtual host file.
<VirtualHost 127.0.0.2:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
And Here is the htaccess from project
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# 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]
</IfModule>
The Error when i access a route link.
Not Found
The requested URL /lara/panel/public/admin was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80
The Problem was the htaccess was hidden my bad i modified it to .htaccess from _htaccess and now it's working.
Your VHost Settings are incorrect. Laravel default serves to localhost:8000. You see it as output after using php artisan serve. Try this:
<VirtualHost *:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>

WordPress As A Symfony (Symfony3) Subdirectory

I am running a Symfony app on DigitalOcean. I have setup the entire site and created VirtualHosts. I need to run WordPress as a subdirectory (/blog). From what I know Symfony tends to ignore subdirectories in /web so I created /web/blog and installed WordPress in it.
<VirtualHost *:80>
DocumentRoot /var/www/html/site.com/web
<Directory /var/www/html/site.com/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
On localhost installations without VirtualHost this runs perfectly.
But on the live server, lets say at 21.21.21.21 I have Symfony running and 21.21.21.21/blog should open blog but it doesn't, instead goes to a Symfony 404. Whereas 21.21.21.21/blog/index.php runs the blog (WordPress).
The WordPress .htaccess which lives in /web/blog is as follows:
Options -Indexes
DirectoryIndex index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I have tried tinkering with this with some answers on the web, nothing changes.
Update your vhost so that you exclude your /blog directory from symphony rules. And you will also need to change to AllowOverride All since you are using .htaccess in /blog.
<VirtualHost *:80>
DocumentRoot /var/www/html/site.com/web
<Directory /var/www/html/site.com/web>
AllowOverride All
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/blog(/.+)? [NC]
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
Be sure to restart apache after changes.
WordPress .htaccess Changes:
Options -Indexes
DirectoryIndex index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Categories