0

I am trying to do something fairly straightforward that I think should be possible without needing to resort to mod_proxy, but can't quite figure it out exactly.

What I want to do is have subdomains - like apply.domain.com/(.*) - rewrite but NOT redirect to a WordPress page - http://domain.com/page/$1

I can get this working as a redirect using the rule below, but cannot seem to figure out how to get it to work ONLY as a rewrite.

RewriteCond %{HTTP_HOST} ^apply\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/apply/$1 [NC,L]

Even though I do not have the R flag, it is still doing it as a redirect, presumably because I have the full domain path in the RewriteRule.

However, if I attempt to omit it...

RewriteRule ^(.*)$ /apply/$1 [NC,L]

I get a 500 error, which doesn't make much sense to me because I have done countless RewriteRules in that fashion and had them work properly with simply a relative path to rewrite to. I figure this must be because of the HTTP_HOST condition.

The next thing I tried was playing with the document root of the subdomain - trying the same root folder as the WordPress site and .htaccess, and also multiple hierarchies of subfolders, differently named than the WordPress page so as to avoid conflict with WordPress' .htacess:

RewriteCond %{REQUEST_FILENAME} !-d

I even tried /subs/apply/ thinking I could then write a very simple rule

RewriteRule ^subs/(.*) http://domain.com/$1 [NC,L]

Which works, but STILL forces it to redirect instead of rewrite.

RewriteRule ^subs/(.*) /$1 [NC,L]

Produces a 500 error.

I have flexibility over the document root of the subfolder and can put it wherever it needs to go in order to achieve this. Just need to get it actually working!

Chris DeMarco
  • 173
  • 1
  • 9

0 Answers0