htaccess allow access from specific domains - .htaccess

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]

Related

.htaccess sitemap rewrite/redirect

I have a single domain, multi store setup on magento 2.3
For example
example.com/jp/
example.com/uk/
however the sitemaps get generated to their store folders within a sitemaps folder in the root dir, such
example.com/sitemaps/jp/sitemap.xml
My google webmaster domains are setup as such
example.com/jp/
So when I need to submit a sitemap it needs to be example.com/jp/sitemap.xml
I've used
#Sitemap: Japan http://www.example.com/sitemaps/jp/sitemap.xml
RewriteCond %{HTTP_HOST} ^.*example\.com$
RewriteRule ^sitemap.xml$ sitemaps/jp/sitemap.xml [NC,L,R=301]
When I access example.com/jp/sitemap.xml its a 404
I'd like example.com/jp/sitemap.xml to redirect to example.com/sitemaps/jp/sitemap.xml
Is there a way of doing this through .htaccess?
You can use this rule as topmost rule in site root .htaccess:
RewriteEngine On
RewriteRule ^[a-z]{2}/sitemap\.xml$ /sitemaps/$0 [L,NC,R=301]
Make sure there is no other .htaccess and this rule is top most rule.

htaccess to redirect from subdirectory to alternate domain

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.

htaccess redirect subdomain to $_GET

Need some help with htaccess
For a sort of image storage site i need this:"
if users come to http:// subdomain.mysite.com/#RANDOMSTRING/ the server has to act like if it is the url: http:// subdomain.mysite.com/index.php?image=#RANDOMSTRING, but the visitor doesnt have to see this.
Also, on www. mysite.com (so not in the subdomain) there is a wordpress with htaccess for seo friendly urls. (Don't know if this has something to do with it, but because i need to upload files for http:// subdomain.mysite.com to ftp:// www.mysite.com/subdomain)
Hope to hear from you, thank you!
In the htaccess file in the subdomain.mysite.com document root add:
RewriteEngine On
RewriteRule index\.php - [L]
RewriteCond %{HTTP_HOST} ^subdomain.mysite.com$ [NC]
RewriteRule ^(.+?)/?$ /index.php?image=$1 [L]
You may not need the RewriteCond at all because it seems your 2 domains (subdomain and www) are in different document roots.

.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]

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

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)

Resources