We only want users from a specific website to use our services. Is there a way to redirect all traffic that does not come from a specific referrer, to a website of our choosing, via htaccess?
Also, this is for the first page only. So if they get to our site, they're going to browse a new page, and their referrer for the new page would apparently be the site they are already on.
Thank you!
Try adding this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteRule ^/?first-page.html$ http://the-website-of-your-choosing.com/ [L,R]
You could also make it so you add your own domain to the referer check:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://your-domain.com [NC]
RewriteRule ^ http://the-website-of-your-choosing.com/ [L,R]
Then you can include all of your pages in the check.
Note that referers can be easily forged and any htaccess file using mod_rewrite in any of your subdirectories will supercede these rules (unless those htaccess files have the RewriteOptions inheret option set)
Didn't work for me, I've made this small change to redirect traffic from google:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.google\.(.*) [NC]
RewriteRule ^(.*)$ https://www.my-site.it/$1 [L,R]
Related
I want to redirect all pages (including subdomains) of an old domain to a single page on the new domain. All pages will be redirect to the same page on the new domain.
I have countless subdomains on the domain I want to redirect. For this reason I need a dynamic code that redirects all pages, because there is no way for me to find all subdomains.
I have pages like this:
old.com
old.com/page1
old.com/page2
sub.old.com
sub2.old.com
sub2.old.com/page
I tried all variations of this code but the subdomains won't redirect:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^old\.com$ [NC]
RewriteRule ^(.*)$ https://new.com/we-moved/ [R=301,L]
If you are using cPanel, Directly use the Redirect Option. IF you want to edit .htaccess file, Checkout my Code:
RewriteCond %{HTTP_HOST} ^clsh\.ga$ [OR]
RewriteCond %{HTTP_HOST} ^www\.clsh\.ga$
RewriteRule ^/?$ "https\:\/\/url\.cloudmate\.in\/" [R=301,L]
This htaccess redirects https://clsh.ga to new Domain https://url.cloudmate.in .
If your htaccess does not redirect then also, try enabling mod_rewrite.c
This should work for you:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} (?:^|\.)old\.com$ [NC]
RewriteRule ^ https://new.com/we-moved/? [R=301,L]
(?:^|\.)old\.com$ will match root domain or any subdomain.
? will discard any query string in redirect.
I have a registration page from my website portal but I want to allow it to be loaded only if the previous domain was the PayPal domain (for example). That way I would garantee that even if a bot scanned my WordPress instance (which is not difficult), it could not register.
I know that mod_rewrite can prevent hotlinking, and allow specific domains to load that content.
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC]
RewriteRule \.(jpe?g|gif|bmp|png)$ https://example/404.jpg [NC,L]
But is it possible using a normal URL? That is, not a file, but a page?
You could use (assuming your registration link is, e.g. /wp-login.php?action=register)
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?paypal.com [NC]
RewriteCond %{QUERY_STRING} ^action=register$
RewriteRule ^wp-login.php index.php [NC,L]
..to redirect to index.php if someone tried to register without coming from paypal (headers can be spoofed, of course)
Yes, you can use the HTTP_REFERER for any URL. Add this to your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?paypal.com [NC]
RewriteCond %{REQUEST_URI} ^/your-registration-url$ [NC]
RewriteRule ^your-registration-url$ https://website.com/404 [R=301,L]
That would redirect anyone visiting your registration URL not having paypal.com as the referrer to a website.com/404 or whatever page you choose to redirect them to.
hoping you could give me some help. I'm trying to re-direct:
http://jaffajava.com/oldsite
To
http://jaffajava.com/oldsite/store
What I've tried so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jaffajava\.com/oldsite\$
RewriteRule (.*) http://www.jaffajava.com/oldsite/store\$1 [R=301,L]
Any help on correcting my syntax/code?
Thanks!
HTTP_HOST variable only matches domain name in the request. You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jaffajava\.com$ [NC]
RewriteRule ^oldsite(/.*)?$ http://www.jaffajava.com/oldsite/store$1 [R=301,L,NC]
Why redirection? Just set new home page, in Configuration -> System -> Site information
I bought two domains:
www.juridischehulponline.nl
www.onlinejuridischehulp.nl
And I'd like them to link to the subfolder of my hosting: www.zuidveste.eu/juridisch and the new domain has to be displayed as the new domain. So if I surf to www.juridischehulponline.nl I'd like to see: www.juridischehulponline.nl and not www.zuidveste.eu/juridisch.
However, if I rewrite and redirect the subfolder to the new domain, I get a: "too many redirects" error. Since it'll go to www.juridischehulponline.nl where an .htaccess is found which will redirect to www.juridsichehulponline.nl
and if I proxy the domain, my new domain keeps being displayed, however simple blogging systems, such as cutenews, won't work, because they see the absolute path as www.zuidveste.eu/juridisch. But due to the .htaccess, that part will be rewritten and the path of www.juridischehulponline.nl/index.php is given; which doesn't exist.
I've deleted the .htaccess in the /juridisch folder, but I don't know how this can be solved.
Can anyone help me?
Regards,
I wouldn't use proxy, but improve the .htaccess-structure: place only a .htaccess in your zuidveste.eu root:
Options -Indexes
RewriteEngine ON
Options +FollowSymLinks
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^juridischehulponline.nl [NC]
RewriteRule ^(.*)$ http://www.juridischehulponline.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^onlinejuridischehulp.nl [NC]
RewriteRule ^(.*)$ http://www.onlinejuridischehulp.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^zuidveste.eu [NC]
RewriteRule ^(.*)$ http://www.zuidveste.eu/$1 [R=301,L]
#rewrite other domains to the subfolder, keeping the attributes
RewriteCond %{HTTP_HOST} ^www.juridischehulponline.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.onlinejuridischehulp.nl [NC]
RewriteCond %{REQUEST_URI} !^/juridisch/
RewriteRule ^(.*)$ /juridisch/$1 [QSA,L]
This code redirects the 3 non-www domains to their www-alternative, so the visitors will see that they are redirected. On the other hand, if they visit the 2 .nl-domains, the urls will be rewritten and the users will not see this change in their address-bar.
Nevertheless, take care for duplicate content in search engines. I recommend using a canonical-meta-tag, as explained here: http://moz.com/learn/seo/duplicate-content
Is there a .htaccess script I can use to redirect the url of an image to an actual web page?
What can I do to make it so when someone accesses an image via their address bar by typing in: http://www.sitename.com/uploads/192-file-name-here.jpg
or other extensions like
http://www.sitename.com/uploads/235-file-name-here.png
It will instead redirect the user to the web page:
http://www.sitename.com/view/192-file-name-here/
I want to still be able to place the images in image tags across the site and on external sites though.
RewriteCond %{HTTP_REFERER} !^https?:\\www\.sitename\.com
RewriteCond %{REQUEST_URI} (.*)\.jpg$
RewriteRule images/(\d+)\.jpg http://www.sitename.com/view/$1.html [L,R=301]
RewriteCond %{HTTP_REFERER} ^$
Can this be modified/re-written to perform my function?
put this in your .htaccess, it will redirect all requests that are sent directly by user.Note: Other sites,as you mentioned can put your images in their pages.
RewriteCond %{REQUEST_URI} ^/uploads/(\d+)-(.+)\.(png|gif|jpe?g|bmp)$ [NC]
RewriteCond %{HTTP_REFERER} ^$
RewriteRule (.*) http://www.sitename.com/view/%1-%2/
Yes you can always redirect images to a webpage or anything using .htaccess.
But images/(\d+).*\.jpg may be better.