0

I have a website that is migrated to another URL. So I wanted to migrate my all previous URL to a new URL with a different segment. For example

  1. Main redirect

    Old site is: https:// myoldsite.abc
    New Site is: https:// mynewsite.xyz

  2. I also want to redirect all other pages to new URL

    Old site is: https:// myoldsite.abc/myfolder
    New Site is: https:// mynewsite.xyz/new_url_1

    Old site is: https:// myoldsite.abc/myfolder/old_url
    New Site is: https:// mynewsite.xyz/new_url_2

    Old site is: https:// myoldsite.abc/myfolder/abc_url
    New Site is: https:// mynewsite.xyz/new_url_3

  3. Simple URLs

    Old site is: https:// myoldsite.abc/testing_url
    New Site is: https:// mynewsite.xyz/New_testing_url_1

My code looks something like this

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^myoldsite.abc [NC,OR]
RewriteCond %{HTTP_HOST} ^www.myoldsite.abc [NC]

RewriteRule ^/myfolder/url_1/?$  https://mynewsite.xyz/new_url_1 [R=301,L]
RewriteRule ^/myfolder/url_2/?$  https://mynewsite.xyz/new_url_2 [R=301,L]
RewriteRule ^/myfolder/url_3/?$  https://mynewsite.xyz/new_url_3 [R=301,L]
RewriteRule ^/myfolder/url_4/?$ https://mynewsite.xyz/new_url_4 [R=301,L]

RewriteRule ^/myfolder?$ https://mynewsite.xyz/new_url_4 [R=301,L,NC] 

RewriteRule ^(.*)$ https://mynewsite.xyz [R=301,L]
</IfModule>
1
  • 1
    To clarify, you are wanting to use .htaccess? However, the directives you have posted are as if you are in the main server config? How many redirects are required? Presumably the old URLs do not exist at the new site? Do both the old and new domains point to the new site? And both domains function OK on the new site - if it wasn't for the redirect? What is the difference between #2 and #3? How are your URLs being routed / what other directives do you have?
    – MrWhite
    Dec 30, 2020 at 1:32

1 Answer 1

-1

Your htaccess file should work, it should be placed in the root directory.

Have you tried Redirect instead?

Redirect 301 /folder/ http://www.example.com/new_path/

9
  • Yes also not working.
    – Viraj
    Dec 29, 2020 at 17:23
  • Apparently you have to have a RewriteCond before each RewriteRule, Try this or Copy/Paste the Cond several times ?stackoverflow.com/questions/7218164/…
    – MeMow
    Dec 29, 2020 at 17:40
  • Is it possible that you can write some solution and I would test it? Thank you.
    – Viraj
    Dec 29, 2020 at 18:18
  • 1
    "Your htaccess file should work" - If these directives are in .htaccess (as suggested) then none of the specific redirects will work due to the slash prefix on the RewriteRule pattern. You don't "have to have a RewriteCond before each RewriteRule" if the old URLs don't exist at the new site. The Redirect directive will likely cause issues, since it is prefix-matching, unless you are particular about the order of the directives, but even then it could result in a malformed redirect - probably best avoided in this situation.
    – MrWhite
    Dec 30, 2020 at 1:42
  • 1
    "Redirect example i sent you works for me" - But be aware that the Redirect example above will also redirect /folder/old_url to /new_path/old_url. So you will need a more specific redirect before this (order matters).
    – MrWhite
    Dec 30, 2020 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .