htaccess redirect to file except own IP - .htaccess

I'm having a bit of a trouble finding the right way to this:
I'm about to launch a site, www.domain.com, but it's not quite yet ready for the public eyes just yet. So I want to redirect all visitors (except myself) to www.domain.com/teaser.html.
How can I do this, so I keep the site content hidden from visitors, without creating a loop if I redirect base url? How would a htaccess string look like?
If I create something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx
RewriteRule .* /coming-soon.html [R=302,L]
It just create a loop. How can I do this without creating a loop?

As mentioned in this question.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteRule index.php$ /teaser.php [R=301,L]

Related

.htaccess forward from one domain to a specific .html page

I know how to use .htaccess to forward everything in one domain to a new domain name. But in this case, I want everything from one domain to go to a specific .html page on a different domain. That's where I'm lost. I'm trying the following but it just redirects to a folder and the page in question is in that folder but obviously, I don't want people seeing the contents of that folder. Make any sense? So example.com needs to go to yyy.com/some-page.html
This is what I'm currently using:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule ^(.*)$ http://www.1.yyy.com/$1 [R=301,L]
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule .* http://www.1.yyy.com/some-page.html [R,L]
You can also put a blank index.html page to the directory in question to mask its contents or
you can put index.php file with this code <? header ("location: http://www.1.yyy.com/some-page.html"); ?> that will redirect a user to the desired page.
$1 is a place holder for the 1st pattern match. So if you are rewriting domaina.com/someurl/, it is attempting to load domainb.com/someurl/. Swap the $1 with the actual page --- e.g. somepage.html and it should work. But unless both of these domains are pointing to the same files/directories, the rule seems a bit overcomplicated.
So how about just a simple redirect?
Try this in your .htaccess file.
redirect 301 / http://somesite.com/somepage.html
OR you can try this.
RewriteRule ^(.*)$ http://somesite.com/somepage.html [R=301,L]
It does work and you can test my RewriteRule below.
http://htaccess.madewithlove.be/
There must be something else going on.

.htaccess redirect to a single page everytime, but keep same url for application reasons

I looked through other stack overflow questions and I couldn't find one that was my exact case.
I have tried writing several different .htaccess rewrite rules but I can't seem to get it working.
I need to do the following:
Original URL: testexample.com/tool/1
Needs to redirect to: textexample.com/tool/display.php
But the URL in the browser needs to stay : testexample.com/tool/1
Can anyone point me in the right direction for rules for this rewrite?
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !display\.php/? [NC]
RewriteCond %{REQUEST_URI} ^/([^/]+)/?.*/? [NC]
RewriteRule .* %1/display.php [L]
Maps silently
http://testexample.com/anything/folder (Shown in the browser all the time)
To
http://textexample.com/anything/display.php

redirect request uri to mirror site using htaccess

I have a website. I created a mirror of it and uploaded it in a directory called 'mirror'. What I wanted to do is whenever a viewer access for example..
http://www.example.com/this-page/another-segment/?id=1
I want him to be redirected to..
http://www.example.com/mirror/this-page/another-segment/?id=1
^^^^^^
(I am doing this because I want to want to edit my site's design but I don't want viewers to see the changes in progress until they are complete. Thus I want to redirect them to the mirrored snapshot, at least temporarily.)
Please suggest how this can be done using .htaccess or not.
after browsing around the internet. i came up with the idea of putting a /$1, a rewritebase and followsymlinks on the answer givien by appclay
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mirror/
RewriteRule (.*) /mirror/$1 [R=301,L]
You'll want to do something like:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mirror/
RewriteRule ^/(.*) /mirror/$1 [R]
In your .htaccess file.

htaccess command to prevent master site access via subdirectory?

I have hosting setup with a master domain (mapped to the web root) and then a number of addon domains (each with their own folder within the web root). At the moment you can visit www.masterdomain.com/addondomainsubdir and reach the same page as you would if you visited www.addondomain.com (which maps to /public_html/addondomainsubdir). I want to prevent this so if you visit www.masterdomain.com/addondomainsubdir then it will do a 301 redirect to www.addondomain.com. The new addondomain.com site is a single page site so it does not have to map any additional pages.
Adding rules to the htaccess file in the web root does notaffect anything as the subdir exists which is wierd as i thought the htaccess command should work even if there is a matching subdir (i've tried the following which works when there's no matching subdir):
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
Logically given it's reaching this directory I figure i need to add a command within the htaccess file in the addondomainsubdir directory however nothing appears to have any effect (i've got various other rules setup and they work fine).
I would be massively grateful if anyone explain the best way to rectify this?
Thanks so much for your help,
Dave
I know this is an old post, but it has never been successfully answered. So for all of you finding this via search, this should do what the OP is asking.
Add this line to your .htaccess file:
redirect permanent /addondomainsubdir/ http://www.addondomain.com
Try these rules in your .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^([^/]+)/?$ http://www.$1.com/ [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^([^/]+)/?$ https://www.$1.com/ [R=301,L]
Instead of putting a rule in your main .htaccess, I would make make a .htaccess for each add-on domain, putting each one in the respective subdirectory.
RewriteEngine on
RewriteCond %{HTTP_HOST} masterdomain\.com$ [NC]
RewriteRule ^addondomainsubdir(.*)$ http://www.addondomain.com/$1 [R=301,L]

Redirect .html but not .html?with=options

I'm currently using an .htaccess to get round a problem with a CMS, nothing major and an htaccess fix is tidy enough.
I'm currently using the format...
redirect 301 /pictures.html http://www.domain.com/gallery.html
The problem though this causes is that the CMS uses pictures.html?vars=here to select galleries and so the redirect breaks this part of it. Is there any way I can redirect pictures.html but not when it has variables attached?
For example, add something like
RewriteCond %{QUERY_STRING} ^$
before your rule.
You can redirect everyone except your webserver by detecting the IP address like so:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=301,L]

Resources