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

nehakakar

New Member
Messages
8
Reaction score
0
Points
1
I have wordpress and site is 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

Code:
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
Code:
# 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
Code:
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?
 

ctyrd

Active Member
Messages
956
Reaction score
80
Points
28
I want to redirect blog.example.com to example.com/blog
Here is my htaccess of example.com/blog
Can't be answered. Need to know the real domain names. x10 hosting subdomain are domains added in the panel. So if it is a domain name you added to your account, "ctyrd.org". Then blog.ctyrd.org will be a domain redirected (or pointer) to a directory of "ctyrd.org". So I would think you will have to use a pointer to "ctyrd.org/blog". File path may not work. "blog.ctyrd.org/wp-admin" may look like, "blog.ctyrd.org/blog/wp-admin".
 

Anna

I am just me
Staff member
Messages
11,758
Reaction score
586
Points
113
Since the domain they'd land on is blog.example.com that one has to exist and the root folder for that one would be where the .htaccess with a redirect needs to be.
It might be possible to set up the subdomain in DirectAdmin and use custom document root and that way point it to the same public_html as your example.com have.
 

nehakakar

New Member
Messages
8
Reaction score
0
Points
1
i have manually test used browser developer tools to inspect network requests and redirects cleared cache, Cloudflare case, tested on online tool like https://redirectchecker.com/ same redirection not working, nothing help to find out the issue.
 

nehakakar

New Member
Messages
8
Reaction score
0
Points
1
Thanks you guys its working i use Redirection plugin now its working as i want...
 
Top