Ask your WordPress questions! Pay money and get answers fast! (more info)

Wordpress old site to new site 301 redirection. WordPress

  • SOLVED

I am looking for some help with wordpress redirection of old subdomain based URLs to new subfolder style URLs. I can give access to a test blog where it can be tested.

The old URL is like

http://blog.oursite.com

and new is http://www.oursite.com/blog

So all old permalinks should 301 redirect to new permalinks

The solution should also take care of https possibility in future, so I can change it to https instead of http.

Should be 10 minutes job for someone who is good with regex :)

Answers (2)

2015-07-23

Navjot Singh answers:

This should work for redirecting from subdomain to subdirectory

RewriteEngine On
RewriteCond %{HTTP_HOST} blog.oursite.com
RewriteRule ^(.*)$ http://oursite.com/blog$1 [R=permanent,L]

For https redirection you will need to add [once you have SSL installed]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


Fahad Murtaza comments:

Hi Navjot. I already have a similar thing in place. I got a redirect loop with the above solution. If I give access, can you have a look?


Navjot Singh comments:

My email id is navjotjsingh [at] gmail [dot] com. Are you getting my message?


Fahad Murtaza comments:

Its still not working for me. Not redirecting. It does show canonical URLS ( Still doesn't redirect) when I try facebook debug tool but no luck otherwise.


Fahad Murtaza comments:

Guys, none of solutions works for me. But I am sure they might work for other people, just not in my specific case. I will split the amount to whoever tried to help.

2015-07-26

IndiTheme - answers:

Redirect http://blog.oursite.com to http://www.oursite.com/blog


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^blog\.oursite\.com$
RewriteRule ^/?(.*)$ http://www.oursite.com/blog/$1 [L,R=301]


Redirect http://blog.oursite.com to https://www.oursite.com/blog

RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^blog\.oursite\.com$
RewriteRule ^/?(.*)$ https://www.oursite.com/blog/$1 [L,R=301,NC]


redirect http://www.oursite.com/blog to https://www.oursite.com/blog

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^oursite\.com\blog [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oursite\.com\blog [NC]
RewriteRule ^/?(.*)$ https://www.oursite.com/blog/$1 [L,R=301,NC]


Fahad Murtaza comments:



RewriteEngine on

RewriteBase /

RewriteCond %{HTTPS} !=on

RewriteCond %{HTTP_HOST} ^blog\.oursite\.com$

RewriteRule ^/?(.*)$ https://www.oursite.com/blog/$1 [L,R=301,NC]



I tried it just now, creates a redirect loop.


IndiTheme - comments:

Oh... but, mine work. Take a look the screenshot.