views:

210

answers:

1

I'm attempting to use .htaccess in the root folder of an Ubuntu/Apache2 server in order to mask a subdomain to subfolder and I keep getting a 500 Internal Error. I know that I'm doing something stupidly wrong and it is some silly error causing the problem. I've checked all of the similar threads on SO and online and whenever I try their advice the 500 continues.

Here's my code.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.mydomain\.com.*$
RewriteRule (.*) intranet/$1 [L]

What I want to occur is that if a user visits admin.mydomain.com they will get the contents of the folder admin.mydomain.com/intranet/ but their URL bar will still be admin.mydomain.com. Any idea what I'm doing wrong?

In addition, some of the threads online talked about possible problems with this system. Is this the best way of doing this masking, should I be using a vhost setup?

A: 

The rewrite rule should work, although I'd probably write

RewriteEngine on
RewriteBase / #omit if in a <Directory> or .htaccess
RewriteCond %{HTTP_HOST} =admin.mydomain.com
RewriteRule ^(?!intranet/).* intranet/$0

Now, you might want to check you Apache error log. It will probably tell you what the error is. My guess is that you did not enable mod_rewrite in httpd.conf.

Artefacto
If I do a apache2ctl -M I see rewrite_module in the list of modules. When I check the apache2 error log I get "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace." I'm new to this server-admin stuff, so any ideas would be helpful?Also, I noticed you changed ^admin\.mydomain\.com.*$ to = "admin.mydomain.com", whats the difference? Same with (.*) to .* and $1 to $0... what do those changes do?
Owen Allen
In addition, I tried the ="admin.mydomain.com" and it doesn't trigger. I did a test redirect RewriteRule .* http://www.mydomain.com, and it doesn't trigger with ="admin.mydomain.com" but it does with ^admin\.mydomain\.com.*$
Owen Allen
@Owen Allen OK, I fixed the recursion with negative lookahead, and removed the quotes around the domain. This should work. `$0` is the global match of the regular expression.
Artefacto