Forum Moderators: bakedjake

Message Too Old, No Replies

mod_rewrite - mysite.org/subdir to subdir.mysite.org

mod_rewrite subdirectory sumdomain htaccess

         

dougpd

2:21 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



Hi,

I've searched the site for the answer, and I've tried many different ways to do this:

I'm on a virtual host (apache 2), root access, not setup as wildcard (using Aliases (CNAME) in my DNS servers)

[mysite.org...] to [subdir.mysite.org...]

( edited to add: both ways work, but I only want subdir.mysite.org )

My httpd.conf:


<VirtualHost [my ip goes here]>
DocumentRoot /var/www/html/forum
ServerName subdir.mysite.org
ServerAlias subdir.mysite.org www.subdir.mysite.org
</VirtualHost>

I've tried this:


Options +FollowSymLinks
RewriteEngine on
AcceptPathInfo on
RewriteCond %{HTTP_HOST} ^subdir\.mysite\org/(.*) [NC]
RewriteRule ^(.*)$ http://subdir.mysite.org/$1 [R=301]

which is as close as I can get to what I thought would work...I;'ve tried other variations from examples, but nojoy...

I did see many examples going from subdomain to subdir, but I need the opposite...

Thanks!
dpd

claus

3:21 pm on Oct 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



These two lines have some minor errors, but apart from those errors they say that; if you are on subdir.mysiteorg, then you should be redirected to subdir.mysite.org:

RewriteCond %{HTTP_HOST} ^subdir\.mysite\org/(.*) [NC] 
RewriteRule ^(.*)$ http://subdir.mysite.org/$1 [R=301]

You might want to change it to this, which says that if you are not ("!") on subdir.mysite.org, then you should be redirected to subdir.mysite.org:

RewriteCond %{HTTP_HOST} 
!
^subdir\.mysite\.org [NC] 
RewriteRule (.*) http://subdir.mysite.org/$1 [R=301,L]

I think this should do it.

/claus

dougpd

3:44 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



Thanks claus, your's worked perfect.

I was close with my original, but no cigar.

I didn't know I could use not ("!") . I also see where my syntax mistakes were...

Thanks for the refresher.
dpd

Monus

4:05 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



If you do it on this way.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdir.domain.com$
RewriteCond %{REQUEST_URI}!^/thesubdir/
RewriteRule ^(.*)$ /thesubdir/$1

than you need less resources, and more important is that you don't serve the visitors and search engines a redirect.

dougpd

8:41 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



Thanks Monus,

I tried your's and I got a 500 error. Anyway, I'm not too worried about the other way, as long as it works. It's only so that if someone tries to access the subdir, they get the subdomain instead. It's new, so search engines aren't an issue. I don't expect many access using this...

Thanks again,
dpd