找到你要的答案

Q:Redirect subdomain to different locations based on url

Q:基于URL重定向域的不同位置

I have a website on a domain that I want to move to another domain. Here is my problem. The root URL has to redirect to a different location on the new domain. Example:

http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location

http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug

The htaccess code that I have doesn't work ver

RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]

This code works for the second example, but nog on the first. Can anyone help me setup the correct htaccess code?

我有一个域的网站,我想移动到另一个域。这是我的问题。根URL必须重定向到新域上的不同位置。例子:

http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location

http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug

我不工作在htaccess代码

RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]

此代码为第二例,但酒在第一。谁能帮我设置正确的.htaccess代码?

answer1: 回答1:

Try:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]

尝试:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]

RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]
.htaccess  redirect