views:

129

answers:

3

I have a subdomain setup as onlinedev.domain.com I need to use htaccess to rewrite to domain.com/online_content, while still showing onlinedev.domain.com in the address bar (SSL is for onlinedev.domain.com). this is what I currently have that is very close:

php_flag display_errors off

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} onlinedev\.domain\.com$ [NC] 
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC] 
RewriteCond %2<->%3 !^(.*)<->\1$ [NC] 
RewriteRule ^(.+) /%2/$1 [L]

This correctly rewrites to domain.com/onlinedev, but if I try to change the RewriteRule to:

RewriteRule ^(.+) /online_content/$1 [L]

I get an error

I understand that there are typically better ways to do this subdomain work, but without getting into server config and DNS details, I need to do it with htaccess.

And yes, I do need to rewrite to a directory that has a different name than the subdomain.

A: 

Which error are you facing? Does the server starts but is not correctly directed or is this a config error?

Cheers, CaioToOn!

CaioToOn
I get the following error:Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Thanks, Josh
Josh Ryan
So please, try to start the server again. Then look at the apache/logs/error.log file. Look at the end of the file and post which error you're having.
CaioToOn
This is the error:[Tue Dec 22 10:15:01 2009] [error] [client xxx.xxx.xxx.xxx] 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., referer: http://onlinedev.domain.com/So, it looks like it is redirecting to much...maybe I need to check to make sure that the rewrite has not already happened? I'm not sure how I would do that though.Thanks.
Josh Ryan
A: 

Well, I figured it out. The issue was that I was causing an infinite loop. Once the rewrite had happened, it was still trying to rewrite to the directory. Here is my new htaccess that took care of it:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} onlinedev\\.domain\\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/online_content/
RewriteRule ^(.+) /online_content/$1 [L]

Notice that I added a check to make sure that the REQUEST_URI is not the name of the directory I am rewriting to.

Josh Ryan
A: 

Try this rule:

RewriteCond %{HTTP_HOST} =onlinedev.example.com [NC]
RewriteCond $0 !^online_content/
RewriteRule .+ /online_content/$0 [L]
Gumbo