So if a visitor is located at the testing site http://testing.site.com/app/article/123qwag how can I redirect him to the same article but in the main app’s domain: http://www.app.com/article/123qwag
Except for me, which I will identify myself through a couple of ips (dynamic ones). Which is the best way to accomplish this, php or .httacces?
Any suggestions?
Edit:
Note: I’m using codeigniter framework
it redirects me to www.app.comindex.php
EDIT2
Ok so here is some of my .htaccess (combined with: https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess)
This .htaccess works great for me, thanks for your help with the redirection
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.com$
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# RewriteCond %{HTTPS} on
# RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REMOTE_ADDR} !=12.23.45.67
RewriteRule ^(.*)$ http://www.app.com/$1 [R=301,L]
# RewriteBase equivalent - Localhost
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule . - [E=REWRITEBASE:/codeigniter-app/]
# RewriteBase equivalent - Development
RewriteCond %{HTTP_HOST} ^testing.app.com$
RewriteRule . - [E=REWRITEBASE:/app/]
# RewriteBase equivalent - Development
RewriteCond %{HTTP_HOST} ^www.app.com$
RewriteRule . - [E=REWRITEBASE:/]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ %{ENV:REWRITEBASE}index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ %{ENV:REWRITEBASE}index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{ENV:REWRITEBASE}index.php?/$1 [L]
#RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
I would use mod_rewrite, because it’s handled directly in the server, thus faster.
1. mod_rewrite solution
You can use the following statements in your
.htaccessto redirect the user to http://www.app.com:Why do we use a 301 redirect here? Because otherwise Google may put your testing site into the index. See here for details: Google and the 301 redirects. This also checks your IP.
Please make sure that mod_rewrite is loaded. On many servers it is not activated by default.
2. PHP Solution
Using PHP would be possible. You need to make sure you route every through these statements, so you can include this in your main config file. It will be slow, but might be easier to deploy, depending on your hosting environment.