URL Redirect 301 blog.example.com to example.com/blog

I have install wordpress at example.com/blog Cloudflare SSL Full (Strict) is enabled with Origin CA certificate installed.
Force HTTPS redirect is enabled on server origin and also on Cloudflare. but i want to redirect blog.example.com to example.com/blog
Here is my htaccess of example.com/blog

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

And here is my blog.examample.com htaccess

I have RewriteEngine On

# Redirect blog.example.com to example.com/blog
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/blog/$1 [L,R=301]

# Redirect example.com/blog to blog.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^blog/(.*)$ https://blog.example.com/$1 [L,R=301]

Now if I check blog.example.com is not redirecting to example.com/blog what is the mistake I did?

0

Comments

3 comments
Date Votes
  • I have checked manually and also checking on online redirect check tool such such as https://redirectchecker.com is also show me same issue

    I want to redirect blog.example.com to example.com/blog any idea?

    0
  • I believe adding this route will be sufficient. Please circle back if you need more help :+1:

    # routes.yaml
    "https://blog.{default}/":
        type: redirect
        to: "https://{default}/blog"
    
    0
  • It is working now thank you so much.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post