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 7677379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:24:33+00:00 2026-05-31T17:24:33+00:00

I am in process of migrating my old domain to new domain using Apache

  • 0

I am in process of migrating my old domain to new domain using Apache Mod-Rewrite moduled and its .htaccess file.
we have almost same structure of the new domain which includes

  1. URL’s
  2. Database

except the domain name, like it was http://www.oldurl.com and now its like http://www.newurl.com and this is what i have in my .htaccess file of Old domain

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldurl.com$
RewriteRule (.*)$ http://www.newurl.com/$1 [R=301,L]

Above settings seems to be working fine except in one case, we have few URL’s in my old domain which has either been removed or structure has been changed so in that case above rule will not work.i came to know about adding something like this in my .htaccess file beside what i have described above

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldurl.com$
RewriteRule (.*)$ http://www.newurl.com/$1 [R=301,L]
Redirect 301 /my-page http://www.newurl.com/your-page

i have total of 20+ such URL’s and i am wondering do i need to map those all 20+ URL to there new URL’s and will i need to take care about any order in which they should be put in the file.

i am also wondering how Apache will work, will it look at each mapped URL for any match? or it works in some other way?

  • 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-31T17:24:34+00:00Added an answer on May 31, 2026 at 5:24 pm

    The Redirect directive won’t be bound to the RewriteCond conditions and will always redirect /my-page to http://www.newurl.com/your-page, also, mod_rewrite has precedence over mod_alias so the RewriteRule (.*)$ http://www.newurl.com/$1 [R=301,L] rule gets applied before the Redirect directive gets looked at. However, if the .htaccess file sits within the document root of both the oldurl.com and newurl.com domains, the Redirect directive will be applied after the browser gets redirected to http://www.newurl.com/my-page, thus redirecting (again) to http://www.newurl.com/your-page

    So, it doesn’t matter what order you have these in, since mod_rewrite gets applied first. If you have 20 URLs that need to redirect to new ones on your new site, you can enumerate them each in their own Redirect. Otherwise, if you’d rather not have the browser get redirected twice, you can enumerate them using the mod_rewrite engine:

    RewriteEngine On
    
    # redirect the changed URLs individually
    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule ^my-page$ http://www.newurl.com/your-page [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule ^my-page2$ http://www.newurl.com/your-page2 [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule ^my-page3$ http://www.newurl.com/your-page3 [R=301,L]
    
    # Finally, redirect everything else as-is
    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule (.*)$ http://www.newurl.com/$1 [R=301,L]
    

    Note that order does matter here. Having to repeat the 2 Conditions for HTTP_HOST is kind of ugly, you can maybe get around that by using the SKIP, but it’s probably better to just repeat them. But if you have access to your server config or vhost config, take a look at the RewriteMap Directive, which allows you to create a mapping of, in your case, old urls to new urls and you can reduce all the individual changed url rewrites to a single one:

    Inside your server/vhost config, something like this:

    RewriteMap newurls txt:/path/to/file/map.txt
    

    Where the /path/to/file/map.txt will look something like:

    my-page your-page
    my-page2 your-page2
    my-page3 your-page3
    etc...
    

    And your combined rules would look like:

    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule ^(.*)$ http://www.newurl.com/${newurls:$1} [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^oldurl.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldurl.com$
    RewriteRule (.*)$ http://www.newurl.com/$1 [R=301,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of migrating to a new PHP Framework. I have
I'm in the process of migrating a website using PHPBB forums to a new
I am in the process of migrating from a Django FastCgi setup in Apache
I'm in the process of migrating some databases. I have this table that has
I am migrating data from a series of old data tables to new tables.
I'm migrating a old (circa 2001) PHP 3 app to a new PHP5 server.
I am in the process of migrating legacy data to a new system. I
Yes this is an old db (we are in the process of migrating). Somehow,
I'm in the process of migrating an App to the current iOS SDK. Its
I'm in the process of migrating some of our old code into Java 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.