Matt Elhotiby
Matt Elhotiby

Reputation: 44066

htaccess redirect not working as thought

Ok so i have an admin folder in a site that i am working and what i need is when someone enters

http://admin.teamfocususa.org/

in their browser then they get redirected to the admin folder

here is my htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^teamfocususa.org [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]

RedirectMatch 301 ^/admin/(.*)$ http://admin.teamfocususa.org/$1

Redirect http://admin.teamfocususa.org /admin

this part is not working

Redirect http://admin.teamfocususa.org /admin

any ideas on how to make this part work ...when i visit http://admin.teamfocususa.org is the home page and not the admin folder as i thought....FYI this is a shared host and I dont have access to the vhost to fix this the way i know

Upvotes: 0

Views: 301

Answers (2)

Michael Berkowski
Michael Berkowski

Reputation: 270607

Try adding a RewriteRule matching on requests to / of admin.teamfocususa.org.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^teamfocususa\.org^ [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?teamfocususa\.org [NC]
RewriteRule ^admin(.*) http://admin.teamfocususa.org/$1 [L,R=301]

# Not needed
#RedirectMatch 301 ^/admin/(.*)$ http://admin.teamfocususa.org/$1

# Added = requests to http://admin.teamfocususa.org/
# Redirected into http://admin.teamfocususa.org/admin
# --OOPS fixed RewriteCond - was typo RewriteRule
RewriteCond %{HTTP_HOST} ^admin\.teamfocususa\.org$ [NC]
RewriteRule ^$ admin/ [L,R=301]

# To hide /admin on admin.teamfocususa.org
# use this instead of the above group...
RewriteCond %{HTTP_HOST} ^admin\.teamfocususa\.org$ [NC]
RewriteRule ^$ admin/ [L]


# Not needed
#Redirect http://admin.teamfocususa.org /admin

Upvotes: 1

mguymon
mguymon

Reputation: 9015

I do not think you want to do a Redirect, but a simple RewriteRule to show the admin folder for the domain admin.teamfocususa.org

RewriteEngine On
RewriteBase /

# If not admin.teamfocususa.org and in /admin folder, redirect to admin.teamfocususa.or
RewriteCond %{HTTP_HOST} ^admin.teamfocususa.org [NC]
RewriteRule ^/admin/(.*)$ http://admin.teamfocususa.org/$1 [L,R=301]

# If domain is admin.teamfocususa.org, show files from admin folder
RewriteCond %{HTTP_HOST} admin.teamfocususa.org [NC]
RewriteRule (.*)$ /admin$1 [L]

# if domain is teamfocususa.org, redirect to www.teamfocususa.org
RewriteCond %{HTTP_HOST} ^teamfocususa.org [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]

UPDATE: My domain checks were wrong, try this updated version

Upvotes: 1

Related Questions