Gold Pearl Gold Pearl - 1 month ago 6
PHP Question

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

Answer

You can use the following rule :

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