使用域目录中的.htaccess将子域重定向到域
我的网页以前是blog.example.com,但现在是example.com.我必须删除/blog目录(该网站位于blog.example.com所在的网站),因为我在URL example.com/blog上有一个Wordpress页面,因此将其搞砸了.
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.
我尝试过:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.example\.com
RewriteRule ^(.*)$ http://www\.example\.com/$1 [L]
以及:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?blog\.example\.com$ [NC]
RewriteRule ^ http://www.example.com/%{REQUEST_URI} [NE,R=301,L]
并且:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
但是,这些子域在子域中没有任何区别. 我该怎么做才能将blog.website.com/URLS重定向到website.com/URLS? (无需创建example.com/blog,因为它会破坏Wordpress的网页网站.com/blog)
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)
我知道了!我必须:
- 从bluehost删除原本应该重定向的重定向 子域到主域
- 在public_html/blog-redirect目录中创建子域blog.example.com
-
将此重定向代码添加到/blog-redirect下的.htacces文件中:
- Remove the redirect from bluehost that was supposed to redirect the subdomain to the main domain
- Create the subdomain blog.example.com at the directory at public_html/blog-redirect
Add this redirect code to the .htacces file under /blog-redirect:
RewriteEngine On
RedirectMatch 301 ^/(.*)$ http://example.com/$1