I have an htaccess to limit the access to files to a direct click in the website. Copy the link send to another one and open it should be forbid.
My htaccess works well
RewriteCond %{HTTP_REFERER} !^http://localhost.*$ [NC]
RewriteRule ^.*$ - [NC,R=403,L]
Now I tried to make it more variable to protocol and host, but now nobody can access the files. The code should do the same as above only with variable http(s) and localhost part ...
RewriteCond %{HTTPS} =on
RewriteRule ^ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^ - [env=proto:http]
RewriteCond %{HTTP_REFERER} !^%{ENV:proto}://%{HTTP_HOST}.*$ [NC]
RewriteRule ^.*$ - [NC,R=403,L]
I don't see the error. Can someone help to solve this?
If you change variables to manual entries, will it work?
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(http://|https://)(www.)?(example.com).*$ [NC]
RewriteRule ^.*$ - [NC,R=403,L]
Related
i am trying to amend my ht access files to redirect access to the site via the https site (rather than the old site)
the first paragraph of ht code below is the part of the access code that only permits access via the root file page.this part works perfeclty.
the second part however is the part that is suppose to re-direct everything to the HTTPS site and prevent access to the http site.This is not working and its still possible to gain access to the site via the http.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
i would really apprciate advise on how to amend the code.
Try and remove the L from the rewrite rule. Once the rule is met it will stop processing so it will always stop.
Change this
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
To
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC]
See how that works for you.
Edit:
If you want to just direct all traffic and non https to https and the index page the code below does the same thing. Notice I used the domain name. Replace yoursite.com with your real site. See how that works.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.yoursite.com/ [R=301,L]
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^(.*)$ / [NC,R=301,L]
I have 2 bits of code that I need help with!
Here is the first, which im trying to redirect the visitors that have no referrer:
RewriteCond %{HTTP_REFERER} ^$
RewriteRule .* http://sitetoredirectto.com [R,L]
and also visitors that type in my url directly (unless its my ip):
RewriteCond %{REMOTE_ADDR} !^28\.473\.38\.251
RewriteRule .* http://sitetoredirectto.com [R,L]
I want to get both of these into the same htaccess file so what do I have to change to get them both to allow only my IP while keeping the functionality they have plus stopping the redirect loop?
You can use it this way:
RewriteCond %{HTTP_REFERER} ^$
RewriteCond %{HTTP_REFERER} !sitetoredirectto\.com [NC]
RewriteCond %{REMOTE_ADDR} !^28\.473\.38\.251
RewriteRule .+ http://sitetoredirectto.com/? [R,L]
I've got a subdomain which i need to disable access too(give a 404).
Example; [abcd.domain.com] - when this url is accessed, the user should receive a 404Page not found.
I have managed to get this working with the code below, BUT, however, its also giving me a 404Page not found EVEN when i browse to [abcd.com]
How could this be modified so it would work both ways?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abcd.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.abcd.domain.com$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ - [L,R=404]
Thank you very much!!
You have an extra [OR] in your conditions.
Simplified rule should be:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?abcd\.domain\.com$ [NC]
RewriteRule ^/?$ - [L,R=404]
So the problem I am currently having is that our entire website is indexed using https. we want to redirect to http using .htaccess. the problem is that we need a couple of URIs to still use https and I am not sure how to write the exception for URIs
I know the below example would work if our site functioned like this www.example.com/account.php but our site urls are like www.example.com/index.php?l=account
# Turn SSL on for account
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
how can i fix this, any guidance would be appreciated.
thanks
EDIT!
So this code below I have working but I would like to make one more exception that I cant seem to get to work, I also want the root (index.php) to only use http.
I tried using...
RewriteCond %{REQUEST_URI} !^/index.php
but this did not work
# invoke rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{https} off
RewriteCond %{QUERY_STRING} !^l=product_detail
RewriteCond %{QUERY_STRING} !^l=product_list
RewriteCond %{QUERY_STRING} !^l=page_view
RewriteRule ^(.*)$ https://%{HTTP_HOST}/development/$1 [R=301,L]
thanks
Try
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/account.php
RewriteCond %{QUERY_STRING} !^l=account
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/account.php [OR]
RewriteCond %{QUERY_STRING} ^l=account
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_REFERER}!(.*)ocean-leecher.net(.*)
RewriteCond %{HTTP_REFERER}!(.*)blindtext.info(.*)
RewriteCond %{HTTP_REFERER}!(.*)yourdomain.com(.*)
RewriteRule ^(.*)$ - [F]
This code accept 3 referrer traffic to all pages of main domain.
Is there any way to make this code valid for just maindomain.com/thankyoupage.php
Add the following
RewriteCond %{REQUEST_URI} ^/thankyoupage.php$
Change your code to this:
RewriteEngine on
RewriteCond %{HTTP_HOST} maindomain\.com$ [NC]
RewriteCond %{HTTP_REFERER} !(ocean-leecher\.net|blindtext\.info|yourdomain\.com) [NC]
RewriteRule ^thankyoupage\.php$ - [F,NC,L]