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]
Related
I have a website domain1.com and all articles include download links to domain2.com like this
http://domain2.com/file1.rar
http://domain2.com/file2.rar
.....
I want only user who is reading article on domain1.com can download above files
Even cannot download if use direct link (without referral from domain1.com)
I try as this guide but fail
Deny referrals from all domains except one
You need to place this rule in DocumentRoot/.htaccess of domain2.com:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !domain\.com [NC]
RewriteRule \.rar$ - [F,NC]
I'm trying to do a simple task with htaccess but I don't have any experiences with htaccess. Basically, this is what I'm trying to achieve.
I have a website (www.example1.com) with a hosting account. And now, I'm launching a second website (www.example2.com) that uses the same hosting account.
Physically the files for www.example2.com exist in www.example1.com/example2.
As you might expect, what I'm trying to achieve is that when a user writes www.example1.com/example2, they are redirected to www.example2.com.
This is what I've tried doing
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^/example1.com/
RewriteRule !^/example2.com/
And also...
Order Deny,Allow
Deny from all
Allow from example2.com
Any help would be appreciated!
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
RewriteRule ^example2(.*) http://www.example2.com$1 [R=301, L]
First line - check if the host matches example1.com with or without the "www.".
Second line - check if the path starts with example2 and, if it does, redirect to www.example2.com, maintaining any existing path after example2.
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)
I have got lots of ideas from google and stackoverflow- but none of those was exactly what i am looking for. here is scenario-
I have bought a hosting space from a provider. I had to provide a domain name(let abc.com) as the primary domain of that hosting space.
Then i have found that i have to put all the contents for that rimary domain(abc.com) into the document root directly. that is no directory like www/abc or www/abc.com.
Then I googled and found lots of .htaccess solution. I picked the following one-
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} abc.com
RewriteCond %{REQUEST_URI} !^/abc.com/(.*) [NC]
RewriteRule ^(.*)$ /abc.com/$1
I have just paste above lines at the end of the existing .htaccess file (default).
It was working fine. I have been using www/abc.com directory for my abc.com domain from then.
Recently I have added some subdomains (let xyz.abc.com) to my abc.com domain. But it is behaving strange with me. all subdomains are looking for its contents from abc.com/subdomain (eg. abc.com/xyz.abc.com)
This time i am getting no solution over google (i may missed it).
Someone help me please- i am in bad shape.
EDITED:
Following lines were in WebRoot .htaccess from the beginning. After that I have added additional lines as mentioned above(3,4)
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName abc.com
AuthUserFile /home/abc/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/abc/public_html/_vti_pvt/service.grp\
EDITED AGAIN:
There are some other domains(except the main domain abc.com) in the same hosting space. Those domains have some working sub-domains. But sub-domain of main domain is not working as i explained above.
Change
RewriteCond %{HTTP_HOST} abc.com
to
RewriteCond %{HTTP_HOST} ^abc.com$
Now the rules do not match your subdomains anymore.
Update
# catch www.abc.com and abc.com (and wwwwwwwwwww.abc.com)
RewriteCond %{HTTP_HOST} ^(w+\.)?abc\.com$
I am looking for the specific .htaccess command that will allow me to deny http access from everyone BUT my scripts.
I have a script that runs out of the root directory that goes and fetches all of the .jpg's out of a given protected directory with the following .htaccess file
<files *.jpg>
order allow, deny
deny from all
</files>
I was thinking something similar to this might work
<files *.jpg>
order allow, deny
deny from all
allow from rootUrl.com
</files>
Your first example should work, since scripts don't make any HTTP requests.
Edit: Unless, your script for some strange reason makes HTTP requests to its own server, which I really don't think it does. Nor should it.
Edit again: Since your script is outputting img elements pointing to the protected files, you have to let all visitors access the files. There is no work-around. You could however stop hotlinking by using .htaccess like this:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ [F]