Home NGINX and htaccess URL rewrite
Reply: 0

NGINX and htaccess URL rewrite

user3373 Published in May 20, 2018, 10:14 am

I have a web application ( built using Laravel 5.5 framework ) hosted on WAMP and apache runs on http. The WAMP is behind NGINX and domain name points to NGINX, basically I have NGINX as proxy to APACHE.

I am using that web application code as generic and dedicated instance with urls like below for multiple clients.


A web app instance can have a specific or dedicated directory like ClientK123 & ClientK456 in apache webroot like below


Similarly more than 1 web app instance can share common code i.e. generic instance and same is available as


I have the mod_rewrite module enabled on APACHE and the rewrite rules for dedicated instances ( ClientK123 and ClientK456 ) are working as expected, but when I try to point some instance ( https://www.testapp.com/ClientK789/ and https://www.testapp.com/ClientK1011/ ) at generic code ( 3rd htaccess Rewrite Condition ) it is doing 307 redirect to the Generic folder with changing the url in the browser to https://www.testapp.com/ClientKGeneric/ But when I tried to access ClientK789 or ClientK1011 using browser on server ( where I have WAMP configured ) with local host or it worked as expected.

Following are the contents of apache .htaccess file

RewriteEngine on 
RewriteBase /

## ClientK2610 
RewriteCond %{REQUEST_URI} ^.*ClientK123/(.*$) [NC]
RewriteRule ^(.*)$ /ClientK123/%1 [QSA,END]

## ClientK2611 
RewriteCond %{REQUEST_URI} ^.*ClientK456/(.*$) [NC]
RewriteRule ^(.*)$ /ClientK456/%1 [QSA,END] 

## ClientKGeneric Generic Codebase - For ClientK789 and ClientK1011
RewriteCond  %{REQUEST_URI} /ClientK(\d+)/(.*$) [NC]
RewriteRule ^(.*)$ /ClientKGeneric/%2 [QSA,L]

Following are the NGINX configuration extracts ( is the private IP of WAMP server )

location /ClientK123 {
        proxy_connect_timeout   1800;
        proxy_send_timeout              1800;
        proxy_read_timeout              1800;
        send_timeout                    1800;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header                Host                    $host;
        proxy_set_header                URI                     $uri;
        proxy_set_header                Referer                 $http_referer;
        proxy_set_header                X-Real-IP               $remote_addr;
        proxy_set_header                X-Forwarded-For         $proxy_add_x_forwarded_for; 

location /ClientK456 {

location /ClientK789 {

location /ClientK1011 {

I ahve checked NGINX and APACHE logs but no 307 redirect traces available, not sure what I am missing or have done anything wrong here.

Please assist.

Thanks, :)

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO