0

In cPanel (at subdomain management) I've set up a wildcard like to following:

*.example.com > public_html/subDomainHandler

Every (non existent subdomain) request like abc.example.com redirects properly to example.com/subDomainHandler.

But requests like abc.example.com/subfolder doesn't redirect to example.com/subDomainHandler.

I am not at my best in regular expressions, but can anybody give me a RewriteCondition for .htaccess?

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • are these rules being written to an .htaccess file? – Menelaos Feb 02 '20 at 20:21
  • Yes they may be written in htaccess. – medicalbird Feb 02 '20 at 20:25
  • There should be no "redirect" here; do you mean "resolve"? Or have you specifically set up a subdomain "redirect" in cPanel? A request like `abc.example.com/subfolder` should _resolve_ to `example.com/subDomainHandler/subfolder` without having to do anything extra? Where is it resolving (or "redirecting"?) to? – MrWhite Feb 03 '20 at 08:46
  • It shoud resolve. Sorry for the typo. – medicalbird Feb 04 '20 at 00:37

1 Answers1

0

Htaccess Rewrite Rule - Try1

I think your answer could be modeled on https://stackoverflow.com/a/8481076/1688441 .

Try the following:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com\(.*)
RewriteRule ^(.*)$ http://example.com/subDomainHandler/$1 [R=301]

Try2

Another option:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule (.*) http://www.example.com/subDomainHandler%1 [R=301,L]

From: https://webmasters.stackexchange.com/questions/13475/redirect-rewrite-subdomain-to-subfolder

Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • So, when setting up a wildcard domain, make sure also to install the SSL for that (wildcard) domain. Sometime's 'old-school-thinking' includes a (little) gap. – medicalbird Feb 02 '20 at 21:52
  • No. But I will test it on another server soon. As I said, the missing SSL is proberbly blocking the (correct?) result of the regular expression.. – medicalbird Feb 04 '20 at 00:38