Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond redirect subdomain to folder, not url

         

LionKing

7:56 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



RewriteEngine on

RewriteCond %{HTTP_HOST} ^sub.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.sub.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/community [R=301,L]

Hello,

I've got this working for a straight redirect of my subdomain. However I don't want it to change the url of my subdomain. What is the syntax for the rewrite to send to the folder public_html/community?

Thanks.

[edited by: jdMorgan at 8:49 pm (utc) on Nov. 22, 2004]
[edit reason] Unlinked example URL [/edit]

jdMorgan

8:48 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the "rewrite" form, as contrasted with the "redirect" form:

RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com
RewriteRule .* /community [L]

Do not end-anchor (with "$") your domain name in patterns. Otherwise, user-agents can "break" your code by adding a port number, which would make the HTTP_HOST look like "sub.domain.com:80"

Literal periods in patterns must be escaped by preceding them with a backslash as shown. An unescaped period means "match any character."

Adding the parenthesized sub-pattern "(www\.)" and following it with a question mark to make it optional eliminates the need for a second RewriteCond.

As with your original code, all requests will end up at "/community" including requests for robots.txt, images, css, scripts, etc. I'll assume that's what you want for now.

Jim

LionKing

8:54 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



That is excellent, I do want everything in the folder.

Thank you.