control access to a folder using .htaccess - only if using particular domain - .htaccess

i have 2 domains pointing to the same site - say a.com and b.com - i have a folder /admin on the site, that i only want to be accessible by people who access using b.com, so b.com/admin would work but a.com/admin would give an access error.
Can this be done through htaccess?
thanks in advance.

order deny,allow
deny from all
allow from 192.168.0.0/24
from http://corz.org/serv/tricks/htaccess.php
i havent tested this but the way he describes it on the website thats what it does.
Otherwise just go with htpasswd.

Use a RewriteCond to check for the current domain, like so:
RewriteCond %{HTTP_HOST} ^a.com [NC]
RewriteRule ^admin/ http://%{HTTP_HOST}/ [R,NC,L]
This will redirect requests from a.com to the root of the site. Requests from b.com can access admin/ just fine.
(from the same site linked-to by slex)

Related

Redirect scam domain to warning?

A client of mine has found out today that someone has set up a spoof domain (1 letter different - design instead of designs) and has tried to set up credit accounts in his name.
The domain will undoubtedly be removed, but is it possible in the meantime using some htaccess trick to check if a visitor to www.designs.com has been referred from www.design.com and if they have, send them to a warning page?
You can use this code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http(s)?://([^\.]+\.)?design\.com
RewriteRule ^.* /warning.html [L,R=302]
It will redirect any pages coming from design.com and its possible subdomains (using http or https) to a page named warning.html at the root of your project.
You can test this rule with this online tool.

.htaccess, DNS & linkstructure

what I'm trying to achieve is forwarding a domain to a subdirectory of my web server.
I need to have several 3rd party domains pointing to the same content whit preserving the link structure.
So no matter if I type in example.com/page1 or example.nl/page1 or example.eu/example1 there should be always the same content.
Any ideas how to achieve that?
If the goal is to server different content under the different domains, assuming you have a directory structure where each domain is a directory under DocumentRoot, you could use:
RewriteEngine On
RewriteCond %{HTTP_HOST} (\.com|\.eu|\.nl)$ [NC]
RewriteRule .* %{HTTP_HOST}/$1 [L,PT,NS]
Otherwise, just pointing DocumentRoot for all domains at the same DocumentRoot will suffice, albeit with SEO risks.

.htaccess redirect to subfolder depending on domain navigated to

I am setting up two wordpress sites on one shared hosting plan for a client. 123-reg says on the decription that many sites can be hosted on the same server so I thought this would be a simple click of a button thing but clearly not.
I have two sites sitting in 2 separate sub directories; FolkstockFestival and FolkstockArtsFoundation. I also have two domains www.folkstockfestival.com and folkstockartsfoundation.com. I need each domain to go to its corresponding sub directory.
I thought you'd be able to do this with the DNS settings but I haven't found a way to do that so I think .htaccess is the way forward. With mod_rewrites, is there a way to direct the user to the right directory depending on which domain is requested? The .htaccess file would be in the root directory.
I do not want the sub-directory to show on the domain so www.folkstockfestival.com shows as is but directs to the correct site.
Many thanks
Use DNS to make both of your domains pointing on your server, and use this htaccess :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www\.folkstockartsfoundation\.com [NC]
RewriteRule ^(.*)$ /FolkstockArtsFoundation/$1 [L]
RewriteCond %{HTTP_HOST} www\.folkstockfestival\.com [NC]
RewriteRule ^(.*)$ /FolkstockFestival/$1 [L]

Redirect But Not Show The URL redirec :: htaccess?

I need to redirect some users, possibly to a subdomain, but I do not want them to know that they are in a subdomain. They should think they are in the main domain.
I believe this can be done with htaccess, but it is gibberish to me.
Can someone please throw me some bones?
When serving content from a different domain without redirecting the browser (thus changing the URL in the address bar) one of two things needs to happen. Either there is a file-path resolution to the other domain, or a reverse proxy must be set up (and it's pretty easy to do if mod_proxy is loaded).
It looks like you have your subdomain inside the document root of your main domain, which means this option will be viable. So if you want to it so when someone puts this URL in their address bar, http://domain.com/page, they get served the content in http://sub.domain.com/another-page, you'd simply add these rules to the top of the htaccess file in the document root of your main domain (public_html):
RewriteEngine On
RewriteRule ^page(.*)$ /subdomain_folder/another-page$1 [L]
Otherwise, the second option is to use mod_proxy:
RewriteEngine On
RewriteRule ^page(.*)$ http://sub.domain.com/another-page$1 [L,P]
EDIT:
I want to redirect some users, depending on their ip (geographic location) to another subdomain. And yes public_html is the root
You can check against the IP via the %{REMOTE_ADDR} variable:
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.89$
RewriteCond !^/subdomain_folder
RewriteRule ^(.*)$ /subdomain_folder/$1 [L]

.htaccess redirect help

I'm a complete newbie to .htaccess. I've been looking around trying to figure this out.
I'm trying to figure how to do the following:
1 web server hosting account
2 different website, call them abc.com and def.com
I want www.abc.com to continue to point to the webroot/Default.aspx. But I want www.def.com to point to www.abc.com/def/Default.aspx while www.def.com still shows up in the address bar.
The admin guy for the server farm I use stated I need to use an .htaccess file. I've been googling around trying to figure this out but only examples I find will redirect every website hit to a server to the subdirectory. I only want www.def.com calls to redirect to the subdirectory.
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteCond %{REQUEST_URI} !^/def.com
RewriteCond %{HTTP_HOST} ^(www\.)?def\.
RewriteRule ^(.*)$ foldername/$1 [L]

Resources