子域的 htaccess 重定向 -> 类似名称的子目录?
我正在重建一个网站,目前有大量内容停放在如下所示的 URL 上。
http://string.domain.com/year/month/ dd/string-pulled-from-title
由于各种原因,我想将所有新内容停放在如下所示的 URL
http://www.domain.com/blogs/string/year/month/dd/string-pulled-from-title< /a>
我想对未来的内容进行更改,但不希望所有旧的内容都进入 404。
我相信我的 htaccess 中的 301 重定向规则可以解决问题,发送所有通过旧内容传入的引用流量指向新格式的链接。
但这个规则应该是什么样的呢? 我读过一些教程,但在任何示例中都没有找到这种确切的情况。
请注意,我不想对所有子域执行此操作,而只想对大约 10 个特定子域执行此操作。 因此,如果有人可以帮助我找出其中之一,那么我可以将其复制粘贴到每个子域的 htaccess 中 10 次并进行设置。
I'm restructuring a web site with a great deal of content currently parked at URLs that look like this.
http://string.domain.com/year/month/dd/string-pulled-from-title
For various reasons, I'd like to park all new content at URLs that looks like this
http://www.domain.com/blogs/string/year/month/dd/string-pulled-from-title
I'd like to make the change for future content, but don't want all the old stuff to go 404.
I believe a 301 redirect rule in my htaccess will do the trick, sending all referred traffic coming in through old links to the new formats.
But what should this rule look like? I've read a few tutorials but haven't found this exact case in any examples.
Note, I don't want to do this for all subdomains, only for about 10 specific ones. So if someone could help me figure out one of these, then I can copy paste it 10 times in my htaccess for each subdomain and be set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其放入旧站点的
.htaccess
文件中(将域调整为您的实际域):这将抓取旧站点 URL 的这一部分:
并将其重定向到新站点新位置:
或者,如果您想要一些更多的变量,例如,无需自定义修复每个
.htaccess
,请将其放入每个子域的文件中:如果您要重定向到同一域,并且包含 www,将重写规则调整为以下内容:
注意第二个
RewriteCond< /code> 检查以确保请求的 URL 不包含前导
www
,如果目标 URL 本身包含www,则可能会导致无休止的重定向
并且也会尝试重定向该子域。%1
从上面的行中获取第一个捕获组。$1
引用同一行上的第一个捕获组。Drop this into the
.htaccess
file of the old site (adjusting the domain to your actual one):This will grab this part of the URL at the old site:
and redirect it to the new site under the new location:
Alternatively, if you want something a little more variable like, without having to custom fix each
.htaccess
, drop this in the file for each subdomain instead:If you're redirecting to the same domain, and it includes the www, adjust the rewrite rules to the following:
Note the second
RewriteCond
which checks to make sure that the URL requested does not include the leadingwww
, which may lead to an endless redirect if the destination URL itself includeswww
and would try and redirect that subdomain as well.%1
grabs the first capture group from the line above.$1
references the first capture group on the same line.