Home Laravel routes not working when site is loaded using reverse proxy
Reply: 1

Laravel routes not working when site is loaded using reverse proxy

Arun D Nambissan
Arun D Nambissan Published in 2018-01-10 07:17:47Z

I am using reverse proxy in my project to redirect a path to a different server.

Site 1: abc.com (server 1)

Site 2: The content is stored in different server which is mapped from a sub-domain of server 1 - testsite.abc.com (server 2)

The site in the server 2 is a laravel project. Where as the site in the server 1 is a normal html site.

The apache configuration to redirect "abc.com/new-url/" to "testsite.abc.com/" using reverse proxy is:

<VirtualHost *:80>
    ServerName abc.com
    ServerAlias www.abc.com
    DocumentRoot /var/www/vhosts/abc-livesite

    <Directory /var/www/vhosts/abc-livesite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All

    ProxyPreserveHost On

    <Location "/new-url/">
        ProxyPass "http://testsite.abc.com/"

The laravel routes are not working for "abc.com/new-url/" without using the index.php. But laravel routes are working fine for "testsite.abc.com/".


The route - "testsite.abc.com/test-route" is working fine.

The route - "abc.com/new-url/test-route" is showing 404 not found error. But "abc.com/new-url/index.php/test-route" is working fine.

I think, here the rewrite rule to override the index.php is not working while using reverse proxy.

The .htaccess file for the site 2 is:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews

    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}]

What is the reason causing this issue? Can anyone help?

Nikhil Reply to 2018-01-16 07:28:28Z

This is a workaround to fix this issue.

Update the reverse proxy rules to resolve the static paths first,

# Add static path

ProxyPass /assets/js http://example.com/js
ProxyPassReverse /assets/js http://example.com/js

ProxyPass /assets/css http://example.com/css
ProxyPassReverse /assets/css http://example.com/css

# Resolve index.php 

ProxyPass /path http://example.com/index.php
ProxyPassReverse /path http://example.com/index.php

This will work as per precedence.

I hope this helps.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298337 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO