Revamping site: 302 redirect htaccess?

3 replies
I am planning to revamp my existing site and have moved all my existing files to a new sub-directory site.com/new

I want all visitors to be redirected there via htaccess, EXCEPT for me (so i can work on the new site)

I have the following code on my .htaccess, but for some reason, it is still redirecting me to mysite.com/new even tho I added in the code to exclude my IP.

Please help.

existing domain: mysite.com
new visitors should go: mysite.com/new
my ip: 11.22.33.44


RewriteEngine on
RewriteCond %{REMOTE_HOST} !^11\.22\.33\.44
RewriteCond %{HTTP_HOST} ^mysite\.com$
RewriteRule (.*) http://www.mysite.com/$1 [R=302,L]
RewriteRule ^$ new [L]
#302 #htaccess #redirect #revamping #site
  • Profile picture of the author Kim Rechter
    Hey Noobcorp,

    Do you have a static IP or a dynamic IP? If it's static try changing {REMOTE_HOST} with {REMOTE_ADDR} and that should do the trick. So your excluded IP line would look like this:

    Code:
    RewriteCond %{REMOTE_ADDR} !^11.22.33.44
    You could also use a temporary maintenance page and then you can use something like:

    Code:
    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^11.22.33.44
    RewriteCond %{REQUEST_URI} !/maintenance.html$
    RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif)
    RewriteRule .* /maintenance.html [R=302,L]
    In this case you'll need to create a file named maintenance.html with whatever message you want your visitors to see and place this file in the directory where your .htaccess file is located (should be root dir).
    {{ DiscussionBoard.errors[6670138].message }}
  • Profile picture of the author Kim Rechter
    Hey Noobcorp,

    Do you have a static IP or a dynamic IP? If it's static try changing {REMOTE_HOST} with {REMOTE_ADDR} and that should do the trick. So your excluded IP line would look like this:

    Code:
    RewriteCond %{REMOTE_ADDR} !^11.22.33.44
    You could also use a temporary maintenance page and then you can use something like:

    Code:
    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^11.22.33.44
    RewriteCond %{REQUEST_URI} !/maintenance.html$
    RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif)
    RewriteRule .* /maintenance.html [R=302,L]
    In this case you'll need to create a file named maintenance.html with whatever message you want your visitors to see and place this file in the directory where your .htaccess file is located (should be root dir).
    Hope this helps some , Kim
    {{ DiscussionBoard.errors[6670143].message }}
  • Profile picture of the author oknoorap
    Few months ago, I found this code and this works for me.

    Code:
    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/$ [NC]
    
    RewriteCond %{REQUEST_URI} !.(css|png|gif|jpe?g|js)$ [NC]
    RewriteRule (.+) http://newdomain.com/$1 [R=303, L]
    {{ DiscussionBoard.errors[6670406].message }}

Trending Topics