Set URLs to redirect to a specific URL without rewriting

I am creating a website that has a structure with several elements, what I am trying to do is assign a custom URL that points to my application for each customer.

So, when a user buys a license from me, I will create my own URL on my web server as follows:

http://webserver/foo.scheduler.com/login 

where foo is the name of the user who purchased the license, and scheduler is part of the default URL, another example with a large number of customers:

 http://webserver/foo.scheduler.com/login http://webserver/foo2.scheduler.com/login http://webserver/foo3.scheduler.com/login 

basically there are three buyers (my customers), each user endpoint allows me to identify the correct database credentials, because in my logic each tenant has a certain db, for more data organization.

In fact, my application is located at this endpoint:

 http://webserver/scheduler 

I want to know if it is possible to point all user urls to http://webserver/scheduler without rewriting the url in the browser, so for example when the user goes to http://webserver/foo.scheduler.com/login true, this is http://webserver/scheduler/login , but the user still continues to see http://webserver/foo.scheduler.com/login .

How can I do that? In my .htaccess , available inside the root of the application folder, I have 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 allows me to rewrite the base path to the index and shunt the trace to a specific controller.

+6
source share
2 answers

Glad to help you with this.

Obtain a valid SSL certificate for * .scheduler.com. You will need it if you are going to make it work. Are you sure you want to use HTTPS? Your other URL is not HTTPS. Then you will need to configure your virtual host for * .scheduler.com to work correctly with this certificate. Only with :

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

There will be nothing of the kind. You need all mod_ssl files to be installed there, as you have with another virtual host. You can simply use this default HTTPS host instead of adding another and changing it.

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

What does the endpoint http://webserver/scheduler mean? This is not a valid domain name. Please clarify what you mean by this, and I will clarify my answer with additional information. Is the code on the same server?

-

Update

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

 <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 maintain / plan, add this to VirtualHost, which was already there. Not new, added above, original at the top.

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

Let me know any problems. If you prefer to put it in your .htaccess, it will need to be updated.

+3
source

Note. I literally accept your claims that the application uses http:// , and clients will use the https:// URL. I also assume that clients get to the same server as the one on which the application is hosted.


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

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

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

You 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> 
+1
source

Source: https://habr.com/ru/post/1014253/


All Articles