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.
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'm having some troubles getting my htaccess rules to work in the intended way. My goal is to redirect any user from example.com to their intended destination that they accessed. However, if the user's referrer is not example.com, I would like it to redirect to a page on my site.
Correct referrer? > URL accessed
Incorrect/unset referrer? > Login page.
My current .htaccess file looks like this:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)*example\.com [NC]
RewriteRule ^(.*)$ http://example.net/login.php [R=301]
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*example\.com [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
However this results in a redirect loop.
Am I doing something wrong here? Any help would be greatly appreciated.
Thanks
One of my site is redirected to another site like this :
http://cccc-xyz.ch is redirected to http://abc.ch
Now want if the redirection is coming from http://cccc-xyz.ch, it should redirect to http://abc.ch/cccc-xyz-page by writing htaccess in http://abc.ch.
I believe this should work
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://cccc-xyz.ch [NC]
RewriteRule ^ http://abc.ch/cccc-xyz-page/ [L,R]
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]
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.