0

I need to create a redirection from my own subdomain to an external subdomain, like subdomain.domain.com -> subdomain.external.com. So if anyone try to enter in my subdomain, it redirects automatically to subdomain.external.com.

Thanks all.

EDIT:

I tried via DNS in cPanel/WHM with CNAME and in .htaccess with:

<IfModule mod_rewrite.c>
RewriteEngine On
SetEnv HTTP_MOD_REWRITE On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$  [NC]
RewriteRule ^(.*)$ https://subdomain.external.com/$1 [R=301,NC,L,QSA]
</IfModule>

But nothing works :/

  • How ? DNS ? Firewall ? .htaccess ? virtual domain ? – xyious May 22 '18 at 15:12
  • Enhanced description – six2dez May 22 '18 at 15:42
  • is mod-rewrite loaded ? – xyious May 22 '18 at 15:47
  • updated, i added entire htaccess – six2dez May 22 '18 at 15:55
  • A CNAME assigns the host name to the same server as some other host name. If you put a CNAME in with where you want the redirect to go, the web server for external site would have to handle the redirect. That could work, but it sounds like you just want to implement the redirect yourself. To implement the redirect yourself, the DNS has to point to your server. – Stephen Ostermiller Jun 24 '18 at 16:26
1

The rules are applied in order, so it would not find a corresponding file and send you to /index.php

<IfModule mod_rewrite.c>
RewriteEngine On
SetEnv HTTP_MOD_REWRITE On
RewriteBase /

# First test for the redirect
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://subdomain.external.com/$1 [R=301,NC,L,QSA]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

The [L], which you can rewrite [last], means that rewrite rules coming after that line are ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.