301 redirect .htaccess

一世执手 提交于 2020-01-06 06:32:15

问题


Im trying to request the following entire site 301 redirect:

word.something.blah.domain.com --> http://www.word.com

I don't know how to write the 301 redirect rule.

Can someone help out?


回答1:


I will assume you are using the same directory to serve files on both domains. In which case, a Redirect clause won't work (infinite redirect loop).

With mod_rewrite, you can check the value of the current HTTP_HOST and take a decision based on that:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.something\.blah\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.%1.com/$1 [R=301,NE,L]



回答2:


put this into root directory of the subdomain:

Redirect permanent / http://www.word.com



回答3:


If you are keeping everything else the same - that is, the file names - but simply changing the domain, this code is all you need to put on the OLD DOMAIN htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]


来源:https://stackoverflow.com/questions/1217209/301-redirect-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!