Gold Pearl
Gold Pearl

Reputation: 2024

Redirect all subdirectory pages to new domain home page in .htaccess

I like to redirect all pages under olddomain.com/subdirectory/ to be redirected to newdomain.com?

The newdomain.com site has a new URL structure, so I want every page under the olddomain.com/subdirectory/urls to be redirected to the newdomain.com homepage.

I tried below code.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomain.com/subdirectory/$ [NC]
RewriteRule ^(.*)$ http://newdomain.com [R=301,L]
</IfModule>

But its redirecting with existing url like http://newdomain.com//url and its through 404 error.

Any help highly appreciated. Thanks

Upvotes: 1

Views: 2901

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

You can use the following rule :

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^subdir/(.*)$ http://newdomain.com/ [R=301,L]
</IfModule>

Upvotes: 4

Related Questions