zbkrt
zbkrt

Reputation: 63

Overwriting 301 Redirect for specific pages

I am moving an old domain to a new domain however some of the old pages are not available. Therefore pages that are still available on the new domain need to be redirected to the new existing page and all others need to be redirected to the overall domain. I am having the following redirect rules:

Updated

//Specific
RedirectMatch 301 ^/(title_1/?)$ https://www.website.com/$1
RedirectMatch 301 ^/(title_2/?)$ https://www.website.com/$1
RedirectMatch 301 ^/(title_3/?)$ https://www.website.com/$1
...

//Overall
RedirectMatch 301 ^/(.*)$ https://www.website.com/blog

However the overall first rule overwrites all the other following rules which are made for the existing subpages. There are about 200 Subpages which are added to the htaccess. Also what I need to mention is that the overall website runs on domain.com/blog but all the subpages that are redirected are just domain.com/title_name_1.

I need the specified 200 pages to not be overwritten by the first rule. Thus not getting redirect to /blog.

I am kind of lost with this. Any help appreciated :)

Thanks

Upvotes: 1

Views: 130

Answers (1)

anubhava
anubhava

Reputation: 786319

Change order of your rules and better to use same directive RedirectMatch for all redirects:

//Example of Redirect for specific pages (about 200+) 
RedirectMatch 301 ^/(title_1|title_2|title_3)/?$ https://www.website.com/$1 

RedirectMatch 301 ^/(category/title_name_2/?)$ https://www.website.com/$1 

//Overall redirect for not specified pages in htaccess
RedirectMatch 301 ^ https://website.com/blog/

Make sure clear your browser cache or use a new browser for testing this change.

Upvotes: 1

Related Questions