views:

20

answers:

1

I'm creating an online community and I'm trying to set up a development server.

Currently, I'm using GIT as my repository. I have both mysite.com and mysite.net; the .com being the primary site.

My Goal:

  • If a user goes to www.mysite.net they should be 301 redirected to www.mysite.com.

  • If a user goes to dev.mysite.net they should be asked for a password and then taken to the testbed.. (on mysite.net/)

Can this be done through some crafty htaccess rewrites?

EDIT:

# Here is what I have so Far
RewriteEngine on

#
## Redirect normal users to mysite.com
#
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

#
## Redirect dev.mysite.net to root directory of mysite.net/
#
RewriteCond %{HTTP_HOST} ^dev.mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]


# REQUIRE Password for Dev Server
AuthUserFile /home/myaccount/public_html/mysite.net/.htpasswd
AuthGroupFile /dev/null
AuthName "Development Server"
AuthType Basic
require valid-user
+1  A: 

Your first goal is simply:

# redirect to primary
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

Remove the www in the RewriteRule if you don't want to prefix.

Please comment back with more information regarding the second goal. I don't understand the testbed part.

Jason McCreary
Okay, good that will redirect the user from www.mysite.net/ to www.mysite.com/. Now for administrators I want to be able to visit www.dev.mysite.net/ and be asked for a password. This will then take the admin to the root of mysite.net and Not redirect them to mysite.com.
pws5068
Is the password protection by HTTP BASIC AUTH or custom?
Jason McCreary
HTTP Auth will work just fine for this case
pws5068
If your .net site is under a separate directory structure in which you can place an .htaccess with HTTP BASIC AUTH, then just copy the above rule and change `(www\.)` to `dev.` and the use the .net address. This will then redirect dev.mysite.net to just the www.mysite.net.
Jason McCreary
Getting closer, the redirections work now. The only problem is that users going to mysite.net/ are still asked for a password before redirecting them to mysite.com. See my edited post above. Thanks!!
pws5068
Sorry, `(www\.)?` to `dev.`. Note the `?`. Also, I don't think you can share the same .htaccess. That's why I said *if* you have a *separate* directory structure. As it is now, it will require authentication for any of your sites.
Jason McCreary
Thanks, I fixed the ? above. I wasn't clear on what you meant by separate directory structures: I assumed you meant between the .net and .com (which are completely separate). If you mean having a subfolder specifically for dev.mysite.net/ then they are the same.
pws5068
I am still unclear on the setup, but you need to put the `AuthType` lines in your .htaccess file for the .net site, provided one exists. That should have it.
Jason McCreary