0

I have a subdomain setup in cPanel, like example.domain.com, and redirecting to domain.com/blah/file.

This works but of course the URL changes to the destination one and does not stick on the subdomain. It won't navigate anywhere as it is pointing to a holding / campaign page but not sure how I can get it to stay on subdomain name but pull in the URL I want it to.

Is there a WordPress addon to help with this, so it can be managed when creating these campaigns in the admin, or a way in cPanel?

halfer
  • 19,824
  • 17
  • 99
  • 186
James
  • 1,668
  • 19
  • 50
  • I have simply setup the subdomain in cpanel control panel which allows redirection – James Apr 21 '15 at 15:13
  • possible duplicate of [.htaccess rewrite subdomain to directory](http://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory) – Bardi Harborow Apr 21 '15 at 15:15

1 Answers1

0

Disable the redirection, point the subdomain to the main document root and edit the .htaccess in your main directory root to include:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ http://domain.com/subdomains/sub/$1 [L,NC,QSA]

Credit to @Ansari's answer.

Community
  • 1
  • 1
Bardi Harborow
  • 1,803
  • 1
  • 28
  • 41
  • Would i place that within main site root? domain.com/ one? – James Apr 21 '15 at 15:18
  • @James, yep, and point the subdomain to the main document root. Obviously you need to change the `sub.domain.com` to your subdomain and `http://domain.com/subdomains/sub/` to the directiory you want to appear when you go to the sub-domain. – Bardi Harborow Apr 21 '15 at 15:20
  • Also should i remove the subdomain and redirection in cpanel? – James Apr 21 '15 at 15:20
  • @James, you need to [disable redirection](https://documentation.cpanel.net/display/ALD/Subdomains#Subdomains-Enableordisablesubdomainredirection) and [point the subdomain to the main document root](https://documentation.cpanel.net/display/ALD/Subdomains#Subdomains-Modifythedocumentrootforasubdomain). – Bardi Harborow Apr 21 '15 at 15:22
  • Super i will give it a go and let you know how it goes. Thanks for your help, i will check it out now. – James Apr 21 '15 at 15:39