Single referrer traffic .htaccess - .htaccess

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]

Related

Redirect IP to Domain Name in AWS [duplicate]

Google search results are showing my pages as (ip)/mypage.html instead of https://www.mydomain.com/mypage.html. I believe the solution is to redirect the ip's to the domain. I've found many, very similar ways to do this, but none of them are working for me. I have an existing rule that redirects http to https. This is what my .htaccess file currently looks like:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^11\.11\.11\.111$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^([a-z.]+)?mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
What am I doing wrong?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]
Alter "111" to your IP
Your 2 rewrite conditions clash. They require http_host to be 11.11.11.111 and to be *.mydomain.com, at the same time. Just add an or like so:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^11\.11\.11\.111$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
update to willian's answer. you just need to replace the domain name (your-domain.io) from this snippet.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$
RewriteRule (.*) https://your-domain.io/$1 [R=301,L]
Hi there we had requirements to do this as well due to a trigger index in the main pub_html folder. These rules should mask the IP to the http (or https if you switch em), make non-www into www. This should also preserve subdomains. This is for (1) simple site sitting in the pub_html, so test with care if you have subdomain triggers or whatever else in your htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.exampledomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^50\.28\.55\.76$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?exampledomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://www.exampledomain.com/$1 [R=301,L]
Hope it helps and works for ya'll. Thanks for the thoughts.

Redirecting from https to http with the exception of some URI's

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]

Domain Management using .htaccess

Suppose all the requests on A.com and B.com end up on the same server, and I want to control the request using htaccess.
The default www content root is /public_html/, but I want A.com requests to be forwarded to /public_html/A/ and B.com requests should be forwarded to /public_html/B/
I came up with this solution:
#/public_html/.htaccess
# A.com
RewriteCond %{HTTP_HOST} ^A.com$
RewriteCond %{REQUEST_URI} !^/A/
RewriteRule (.*) A/$1 [L]
# B.com
RewriteCond %{HTTP_HOST} ^B.com$
RewriteCond %{REQUEST_URI} !^/B/
RewriteRule (.*) B/$1 [L]
and I am having two problems with it:
A.com/A/index.php and A.com/index.php are the same thing, which is not cool! I'd rather the user be 301-ly redirected to the latter whenever he uses the former.
A.com/etc redirects to A.com/A/etc/
Overall, I don't want my visitors to see the /A/ (or /B/) in the URL anyway. Any htaccess solution is welcome.
You can use this code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# for external redirection of A.com/A/foo to A.com/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/*(A|B)(?:/(.*)|)\s [NC]
RewriteRule ^ http://%1.com/%2 [R=301,L,NC]
# for internal redirection of A.com/foo to A.com/A/foo
RewriteCond %{HTTP_HOST} ^(A|B)\.com$ [NC]
RewriteRule (?!^(A|B)(?:/(.*)|)$)^.*$ %1%{REQUEST_URI} [L]
Add this to your .htaccess in the same order:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^(A|B)(?:/(.*))?$ http://%{HTTP_HOST}/$2 [NC,L,R=301]
#/public_html/.htaccess
# A.com or B.com
RewriteCond %{HTTP_HOST} ^(A|B).com$ [NC]
RewriteRule (.*) %1/$1 [L]
If you do not want A to be redirected to A when accessed like this A.com/B/. or If you do not want B to be redirected to B when accessed like this B.com/A/. You can throw a 404 error.
RewriteCond %{HTTP_HOST} ^A.com$ [NC]
RewriteCond %{REQUEST_URI} ^/B(?:/(.*))? [NC]
RewriteRule ^ - [L,R=404]
RewriteCond %{HTTP_HOST} ^B.com$ [NC]
RewriteCond %{REQUEST_URI} ^/A(?:/(.*))? [NC]
RewriteRule ^ - [L,R=404]
Add the above lines right afterRewriteRule ^ - [L] before RewriteRule ^(A|B)(?:/(.*....

Temporary redirect to maintenance page

I am trying to write a rule to redirect all URLs to a temporary page so that some site updation could be done, but it ends up in an infinite loop.
RewriteCond %{HTTP_HOST} ^(.*)mysite\.com$
RewriteCond %{REQUEST_URI} !^(.*)temp$
RewriteRule ^(.*)$ http://www.mysite.com/temp [R=307,L]
How to check if it's a temp page?
You need to write rule for all request except maintenance file.
.htaccess should be:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
What I do is to redirect all traffic to a maintenance.html page when it's not coming from my IP.
The first rewrite condition avoids an infinite loop.
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^172\.16\.254\.1$
RewriteRule $ /maintenance.html [R=302,L]
It works, I tried it. It will redirect all requests to a maintenance page.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

How would I redirect two domains using .htaccess

I'm trying to redirect one domain to the root and another to a directory. The problem I'm having is the second domain is overwriting the firsts redirection.
Here is what I have.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://example.site.net$ [NC]
RewriteCond %{REQUEST_URI} !^/.*$
RewriteRule ^(.*)$ / [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://example2.com [NC]
RewriteCond %{HTTP_HOST} !^http://www.example2.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} !^/example2_directory/
RewriteRule ^(.*)$ /example2_directory/$1
That's because 'example2.com' and 'www.example2.com' are not 'example.site.net', like your .htaccess rule states...
If you want those rules to apply to those specific domains, you need to remove the '!' in front of them. Otherwise you need to explain what specific domains need to point to what, not just 'one domain' and 'the other domain'.
Edit: Also, you're not supposed to include the 'http://' for your HTTP_HOST conditions.
I think you might not realize you're negating your comparisons with "!"
Also, you dont' have to turn the engine on twice.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://example.site.net$ [NC]
RewriteCond %{REQUEST_URI} !^/.*$
RewriteRule ^(.*)$ / [L]
RewriteCond %{HTTP_HOST} ^http://example2.com [NC]
RewriteCond %{HTTP_HOST} ^http://www.example2.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} !^/example2_directory/
RewriteRule ^(.*)$ /example2_directory/$1

Resources