0

I would like to rewrite requests to a subdomain to a sub-folder on the site in question.

The subdomain is dev.my-domain.co.za (yes, it has a hyphen in it)

The folder it needs to internally reference is my-domain.co.za/dev.my-domain.co.za

I don't want it to redirect, but to rewrite, so that the user just sees http://dev.my-domain.co.za/...

I found various examples here on StackOverflow, but I was unable to get them to work in my scenario. So I figure it's best I ask and explain my exact situation.

There is going to be a Wordpress site in the sub-folder. I am assuming it is okay to call it via a sub-domain (if you happen to know, please advise). Otherwise, if there are issues, I can ask that question separately in a WP related forum.

So far I tried this:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^dev\.domesticflights\-southafrica\.co\.za.*$
RewriteRule (.*) dev\.domesticflights\-southafrica\.co\.za/$1 [L]

Which is my attempt to apply this (from here) to my scenario

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) myfolder/$1 [L]

I tried adapting many other examples, but none work in my scenario.

Community
  • 1
  • 1
inspirednz
  • 4,807
  • 3
  • 22
  • 30

1 Answers1

0

You can try these rules to internally redirect from

dev.my-domain.co.za to my-domain.co.za/dev.my-domain.co.za

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www)(.+)\.(my-domain\.co\.za)$
RewriteRule ^ http://%2/%1.%2 [P]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • Thanks Jack. Seems to have had no effect whatsoever. I am beginning to wonder if this server environment is set up strangely (it's a server and host I am not familiar with). – inspirednz Jun 21 '16 at 22:20
  • Ok, check to see if your htaccess file use is enabled in the apache config. It should be `AllowOverride All` Also I updated my answer because you will need to proxypass to the subfolder using the `[P]` flag or apache will do a redirect. – Panama Jack Jun 22 '16 at 02:59