Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:18:12+00:00 2026-05-29T08:18:12+00:00

So if a visitor is located at the testing site http://testing.site.com/app/article/123qwag how can I

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:18:13+00:00Added an answer on May 29, 2026 at 8:18 am

    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 .htaccess to redirect the user to http://www.app.com:

    RewriteEngine On
    RewriteBase /app
    RewriteCond %{HTTP_HOST} ^testing.app.com$
    RewriteCond %{REMOTE_ADDR} !=12.34.56.78
    RewriteCond %{REMOTE_ADDR} !=12.34.56.79
    RewriteRule ^(.*)$ http://wwww.app.com$1 [R=301,NC]
    

    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.

    <?php
    if($_SERVER['REMOTE_ADDR'] != "12.34.56.78" && $_SERVER['REMOTE_ADDR'] != "12.34.56.79") { // Your IPs
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://www.app.com/".str_replace("/^\/app/","",$_SERVER['REQUEST_URI']));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Redirecting a visitor who hits http://example.com to http:// www .example.com isn't terribly difficult. But
Background info I have an app where users can make microsites ala http://myname.the_app.com .
I'm trying to redirect every visitor that tries to enter my homepage (http://www.mysite.com/) to
Consider a webpage, located at http://www.example.com/mypage.html Unfortunately, someone wrongly advertises that the page's address
Is it possible to implement the Visitor Pattern respecting the Open/Closed Principle , but
How can I gather the visitor's time zone information? I need both: the time
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
i have wrote the visitor pattern as follow but i don't understand what is
is it possible to redirect a visitor on my php page as soon as
My project is a visitor app for a University, that basically displays places and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.