Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect all pages under a folder to new domain

I have some files placed under a particular folder in my old domain like this: http://www.olddomain.com/folder1/.

I want to redirect all requests that try to access files under this folder to a new domain. Example: http://www.olddomain.com/folder1/page1.html -> http://www.newdomain.com/page1.html

How do I accomplish this using .htaccess?

like image 280
Bijoy Thangaraj Avatar asked Dec 07 '11 13:12

Bijoy Thangaraj


People also ask

How do I redirect a whole website to another domain?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

How do I redirect a folder?

Right-click a folder that you want to redirect (for example, Documents), and then select Properties. In the Properties dialog box, from the Setting box, select Basic - Redirect everyone's folder to the same location.


1 Answers

Give this a shot.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

</IfModule>
like image 118
brpyne Avatar answered Oct 06 '22 20:10

brpyne