Reputation: 360
I have two identical versions of a website, both using different AWS EC2 instances(staging xx.xx.xx.xx and production xxx.xxx.xxx.xxx). I want to create a 301 redirect that redirects all users from the staging site to the production site, UNLESS they are visiting from my IP. I thought this was a relatively simple task, but I have attempting to make this work for the last couple hours with no resolution. I am hoping that someone here will be able to point me in the right direction. Currently, the redirect works for visitors to the homepage http://xx.xx.xx.xx, but it does not work for other pages such as http://xx.xx.xx.xx/page1 or the ec2 public DNS like http://ec2-xx-xx-xx-xx.us-west-1.compute.amazonaws.com/ Here is my entire .htaccess file, the redirect I added is the last one. Any help you could give me would be much appreciated!!
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
# END WordPress
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
RewriteBase /
RewriteCond %{HTTP_HOST} !newsite.com$ [NC]
RewriteCond %{REMOTE_ADDR} !=xxx.xxx.xxx.xxx
Upvotes: 6
Views: 11232
Reputation: 360
Thanks for your help, I wanted to post the solution I found in a wordpress forum here: https://wordpress.org/support/topic/htaccess-help-301-redirects-not-working/ Thanks to @markrh for his answer. The problem was that I needed to move my 301 redirects above the WordPress section at the top. My rules were never getting reached cause the WordPress part catches all of them.
Upvotes: 3