Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I 301 redirect specific subdomain URLs using .htaccess?

I need to redirect particular URLs on a subdomain to completely different URLs on a different subdomain. For example:

http://foo.example.com/this-is-my-page

Needs to 301 to:

http://bar.example.com/this-is-really-my-page

I’ve tried setting up a simple Redirect 301 in .htaccess but it doesn't seem to work. For example:

Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page
like image 292
Finch Avatar asked Mar 23 '12 19:03

Finch


People also ask

How do I redirect a subdomain to a URL?

Under Modify a Subdomain, locate the domain you want to redirect, then click its Manage Redirection link on the right. In the text box, type the URL you would like visitors to be redirected to if they go to the subdomain sample1.hgexample.com. Click Save. You will see the redirected URL under the Redirection column.

What is a 301 .htaccess redirect?

A 301 Permanent Redirect permanently redirects one URL to another. You set up a 301 redirect using . htaccess to send visitors to a new URL and tell search engines that a page has moved so that the new page can be properly indexed. Some common uses of a 301 redirect with .


1 Answers

try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) http://newsub.domain.com/ [L,R]

it works on my side

like image 127
aldo Avatar answered Oct 23 '22 03:10

aldo