Click to See Complete Forum and Search --> : Onion Layer


JunkDrawStuff
01-30-2010, 08:03 AM
I want to add a layer of security to an admin login link on a server, well three domains so I want to write one .htaccess file that I can just upload to each server to deal with this problem.

I have very limited understanding of URL rewrite and try this
Options +FollowSymLinks
Options -Indexes
RewriteEngine On

# We need to test the URL to see if the request is for the admin URL
# 1. if the URL has /cms/admin/ in the REQUEST_URI and
# 2. if the DOMAIN has admin. as the subdomain, we issue the admin pages
RewriteCond %{REQUEST_URI} ^/cms/admin/$ [NC]
RewriteCond %{HTTP_HOST} ^admin\.(.*)/$ [NC]
RewriteRule .* http://$1/cms/admin/ [L]

# We need to test the URL to see if the request is for the admin URL witout the prefix
# 1. if the URL has /cms/admin/ in the REQUEST_URI and
# 2. if the DOMAIN has not got admin. as the subdomain, we issue the site root pages
RewriteCond %{REQUEST_URI} ^/cms/admin/$ [NC]
RewriteCond %{HTTP_HOST} !^admin\.(.*)/$ [NC]
RewriteRule .* http://$1/cms/ [L]

# if we get here, its likely nothing matched, so do nothing to the URL
RewriteRule .* - [L]

Problem is that the redirect try directing to http://cms/ which is invalid.

What I want to do is use the URL admin.thedomainname.com/cms/admin/ to allow access to the page for login but thedomain.com/cms/admin/ to push access to the site root page.

The aim being that I can change the admin to whatever I want so that I could use systemadmin.thedom..... or pepperonichees.thedom... or whatever I alter admin to in the htaccess file to stop people trying to login to the CMS that I am using that is installed on the server in the /cms/ folder.

I already had help with redirection for site root to /cms/ folder, I now need to stop the thousands of hits on the /cms/admin/

Can someone tell me what I am doing wrong?

Thank you.

aj_nsc
01-30-2010, 04:04 PM
You're not actually 'matching' anything so $1 is nothing

Replace these lines


RewriteRule .* http://$1/cms/admin/ [L]

...


RewriteRule .* http://$1/cms/ [L]


with these:


RewriteRule (.*) http://$1/cms/admin/ [L]

...


RewriteRule (.*) http://$1/cms/ [L]

JunkDrawStuff
01-31-2010, 03:58 AM
Really confused now... I get

http://www.cms.co.uk/admin//cms/

When I test a url that is http://somedomain.org/cms/admin/

Where did the .co.uk bit come from?

JunkDrawStuff
01-31-2010, 04:23 AM
So the $1 only works on the line that is is on then?

I though the back reference was for storage and later use.

So how does the %1 thing work then.