[英]How do you redirect a domain to a subdomain?
我正在尝试将http://www.gelda.com/web_pages/food_index.html重定向到http://food.gelda.com/ 。
我尝试了以下方法:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
Redirect 301 /web_pages/ http://food.gelda.com/
</IfModule>
这没有用,它已重定向到http://food.gelda.com/food_index.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^gelda.com/web_pages/food_index.html$ [OR]
RewriteCond %{HTTP_HOST} ^www.gelda.com/web_pages/food_index.html$
RewriteRule ^(.*)$ http://food.gelda.com/ [R=301,L]
</IfModule>
这也重定向到http://food.gelda.com/food_index.html
我不确定如何在我的.htaccess文件中进行此操作。 我需要/web_pages/
任何内容才能访问food.gelda.com
。
基于重写模块的两种选择:
您可以使用http服务器主机配置(首选)或在主机文档根文件夹(与/web_pages
文件夹平行 )中使用动态配置文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gelda\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gelda\.com$
RewriteRule ^/?web_pages/ http://food.gelda.com/ [R=301]
或者,您可以使用主机/web_pages
文件夹中的动态配置文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gelda\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gelda\.com$
RewriteRule ^ http://food.gelda.com/ [R=301]
显然,在所有情况下,都需要加载和激活重写模块。 如果决定使用动态配置文件( .htaccess
样式文件),则需要使用http服务器主机配置中的AllowOverride
指令启用其解释。 显然,该文件还需要服务器进程读取。
还有一个一般性提示:您应该始终喜欢将此类规则放置在http服务器(虚拟)主机配置中,而不是使用动态配置文件( .htaccess
样式文件)。 众所周知,这些文件容易出错,难以调试,并且确实降低了服务器的速度。 仅当您无法控制主机配置(阅读:真正便宜的托管服务提供商)或者您的应用程序依赖于编写自己的重写规则(这显然是安全噩梦)时,才将它们作为最后一个选项来支持。 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.