Grant
Grant

Reputation: 7

htaccess - redirect directory but not sub directory

I need to create a .htaccess redirect file that redirects all traffic from an old domain (olddomain.com/feedback/) to a new domain (newdomain.com). However i do not want traffic to redirect traffic to olddomain.com/feedback/form/customer-feedback/ and wish for that to still go to the original destination.

Here is what i have created to date.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/feedback/form/customer-feedback
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

Upvotes: 0

Views: 199

Answers (2)

anubhava
anubhava

Reputation: 785146

You can use this rule in old server's root .htaccess:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^feedback/?$ http://www.newdomain.com/$1 [R=301,NC,L]

Upvotes: 0

Rounin
Rounin

Reputation: 29463

Almost perfect.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^feedback/form/customer-feedback
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

On the second line, I have removed the slash immediately preceding feedback/.

When you compose mod_rewrite directives, whatever follows the start-of-match indicator ^ is what comes after the immediately preceding slash in the URI.

Upvotes: 1

Related Questions