问题描述
比方说,我的域名是 website123.com 和我有一个子域的 my.website123.com
Let's say my domain name is website123.com and I have a subdomain of my.website123.com
我已经从网站中删除了我的子域,并希望确保任何人去任何页面与my.website123.com网址被重定向到主www.website123.com URL。 我的子域有一吨的它的网页,所以我需要确保该页面,无论用户去对我的子域,他们将被重定向到该网站的主索引页
I've deleted the "my" subdomain from the site and want to make sure that anyone that goes to any page with a my.website123.com URL is redirected to the main www.website123.com URL. The "my" subdomain has a ton of pages of it, so I need to make sure that regardless of which page a user goes to on the "my" subdomain, that they're redirected to the site's main index page.
我在想打通的.htaccess这个成就 - 是最好的方法是什么?如果是的话怎么样?
I was thinking to get this accomplished through .htaccess - is that the best way? If yes how?
推荐答案
@ joeh0717
@joeh0717
是的,对于一个.htaccess文件修改到这一点:
Yes, for an .htaccess file modify it to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteRule /(.*) http://www.domain.com [R=301,L]
</IfModule>
请注意,此code已经在你的子域的根目录下。如果像您前面提到的,你已经删除了该子站点,你将需要重新建立,并把这个.htaccess文件的根目录。
Note that this code has to be in the root directory of your subdomain. If, as you mentioned before, you've deleted this subdomain, you're going to need to re-establish it and put this .htaccess file in the root.
这篇关于如何设置一个子域的所有页面重定向到一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!