简体   繁体   English

重定向子域并保留url结构

[英]redirect subdomain and retain url structure

I'm redirecting a wordpress blog that lived in a subdomin to my root. 我将一个子域中的wordpress博客重定向到我的根目录。 when i visit links from my old blog, they just redirect to the index page of my blog, but i need them to redirect to the actual post. 当我从旧博客访问链接时,它们只是重定向到我博客的索引页面,但我需要它们重定向到实际帖子。 for example - 例如 -

sub.mysite.com/1/2/3 - should redirect to -  mysite.com/sub/1/2/3

how can this be done? 如何才能做到这一点? thanks! 谢谢!

UPDATE - still haven't found a solution for this. 更新-尚未找到解决方案。 Anyone? 任何人?

OR is there another post here that already exists that will show me the correct way to do this? 还是这里已经存在另一篇文章,将向我展示正确的方法? THANKS! 谢谢!

The alternative approach is by editing your web server configuration. 另一种方法是通过编辑Web服务器配置。

Apache's rewrite rules can do this. Apache的重写规则可以做到这一点。 You most likely have a .htaccess file in the root directory of your blog. 您很可能在博客的根目录中有一个.htaccess文件。 Append the text below to it. 将下面的文本添加到该文本。 If there is no such file, create one. 如果没有这样的文件,请创建一个。

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

Your web server has to be configured to accept this configuration from a .htaccess file. 您的Web服务器必须配置为接受来自.htaccess文件的此配置。 It can also be placed in the configuration directly. 也可以直接将其放置在配置中。 The procedure for this differs depending on your web host. 此过程取决于您的Web主机。

The Wordpress Redirection plugin should be able to do exactly what you need. Wordpress重定向插件应该能够完全满足您的需求。

If it doesn't, you can also accomplish this using your web server's configuration, but it's more complex to set up. 如果不是这样,您也可以使用Web服务器的配置来完成此操作,但是设置起来比较复杂。 See my second answer on this page. 请参阅此页面上的第二个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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