简体   繁体   中英

Set urls for redirect to a specific url without rewrite

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:

http://webserver/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:

http://webserver/foo.scheduler.com/login
http://webserver/foo2.scheduler.com/login
http://webserver/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 http://webserver/foo.scheduler.com/login in the true is http://webserver/scheduler/login , but the user still continue to see http://webserver/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.

Happy to help you with this.

Get a valid SSL certificate for *.scheduler.com. You are going to need that if you're going to get this to work. Are you sure you want to use HTTPS? Your other URL is not HTTPS. Then you will need to set up your virtual host for *.scheduler.com to work properly with that certificate. Only having :

<VirtualHost *:443>
    ServerAlias *.scheduler.com
    DocumentRoot "/var/www/html/progetti/scheduler"
</VirtualHost>

Is not going to be anything like enough. You need all the mod_ssl stuff setting up in there as you have with the other virtual host. You could just use that default HTTPS host instead of adding another one, and modify it.

The first thing to do is get your hosting working for https://*.scheduler.com/ and then just point it at the right place.

What do you mean your endpoint is http://webserver/scheduler ? This is not a valid domain name. Please clarify what you mean by that and I will update my answer with more information. Is the code on the same server?

--

Update

So to do this without SSL, add the following to your "000-default.conf", after what is currently there:

<VirtualHost *:80>
    ServerAdmin localhost@gmail.com
    ServerName www.scheduler.com
    ServerAlias *.scheduler.com
    UseCanonicalName off
    DocumentRoot /var/www/html/progetti/scheduler
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/html/progetti/scheduler>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

--

Update

To make http://webserver/foo.scheduler.com work and serve /scheduler, add this to the VirtualHost that was already there. Not the new one added above, the original one at the top.

RewriteEngine on
RewriteRule ^(/[^./]+\.scheduler\.com)(?:$|/(.*)$) /scheduler/$2

Let me know any problems. If you would prefer to put it in your .htaccess it will need updating.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM