I have a main domain mydomain.com and a subdomain m.mydomain.com, both are SSL secured.
When I access the subdomain m.mydomain.com I want to be redirected on mydomain.com/mobile.php/nb without changing the url…so the url must remain m.mydomain.com
Here is what I came up:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^m.mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.m.mydomain.com$
RewriteCond %{REQUEST_URI} !^/.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule ^(.*)$ "https://mydomain.com/mobile.php/nb$1" [R=301,L]
It redirects me right but it doesn’t keep the subdomain url address.
All the solutions I’ve found works only if the sites are not secured(http).
2
Answers
It can, but shouldn’t be done via the .htaccess file.
This is normally done wihtin your vhost config file
Source: https://wiki.apache.org/httpd/RedirectSSL
The mod-rewrite
R
flag performs an external redirection of urls from old location to the new one. If you do not want to redirect your subdomain remove theR=301
flag from your RewriteRule and use an absolute path instead of the full url as Rewrite destination.This will internally redirect
www.m.domain.com
orm.domain.com
to/mobile.php/nb/
.