Sunday, January 29, 2017

Set urls for redirect to a specific url without rewrite

Leave a Comment

I'm building a webscheduler that have a multitenant structure, what I'm trying to do is assign a custom url that point to my application to each buyer.

So essentially when a user buy a license from me, I'll create a custom url on my webserver like this:

https://foo.scheduler.com/login 

where foo is the name of the user that has buyed the license, and scheduler is a default part of the url, another example with more buyers:

https://foo.scheduler.com/login https://foo2.scheduler.com/login https://foo3.scheduler.com/login 

essentially there are three buyers (my customers), each custom endpoint allow me to identify the correct database credentials, 'cause in my logic each tenant have a specific db, for more data organization.

Actually my application is located to this endpoint:

http://webserver/scheduler 

I want to know if is possible point all custom urls to http://webserver/scheduler, without rewrite the url in the browser, so for example when the user go to https://foo.scheduler.com/login in the true is http://webserver/scheduler/login, but the user still continue to see https://foo.scheduler.com/login.

How can do this? In my .htaccess, available inside the root of the application folder I've this content:

RewriteEngine On  RewriteBase /webscheduler/  RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l  RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

this allow me to rewrite the base path to the index, and shunt the trace to the specific controller.

1 Answers

Answers 1

Note: I'm taking literally your statements that the app is using http:// and the clients will use https:// URLs. Also I'm assuming that the clients are hitting the same server as the one that hosts the app.


Probably the simplest way to do this is to configure one VirtualHost for your actual application and a separate one for the other URLs.

So assuming your application lives in /var/www/html/scheduler, then your existing VirtualHost looks like:

<VirtualHost *:80>    ServerName webserver    DocumentRoot "/var/www/html" </VirtualHost> 

You would need to add change your conf.d/ssl.conf to have something like:

NameVirtualHost *:443  <VirtualHost *:443>     ServerAlias *.scheduler.com     DocumentRoot "/var/www/html/scheduler" </VirtualHost> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment