简体   繁体   中英

Redirect subdomain to domain with .htaccess in domain directory

My webpage used to be blog.example.com, but it is now example.com. I had to delete the /blog directory (where the website hosted blog.example.com), because I have a Wordpress page at the URL example.com/blog and that screws it up.

I have tried:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.example\.com
RewriteRule ^(.*)$ http://www\.example\.com/$1 [L]

As well as:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?blog\.example\.com$ [NC]
RewriteRule ^ http://www.example.com/%{REQUEST_URI} [NE,R=301,L]

And:

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

But none of these make any difference in the subdomain. What can I do to redirect blog.website.com/URLS to website.com/URLS? (without creating example.com/blog because it will mess up Wordpress's webpage website.com/blog)

I figured it out! I had to:

  1. Remove the redirect from bluehost that was supposed to redirect the subdomain to the main domain
  2. Create the subdomain blog.example.com at the directory at public_html/blog-redirect
  3. Add this redirect code to the .htacces file under /blog-redirect:

     RewriteEngine On RedirectMatch 301 ^/(.*)$ http://example.com/$1 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM