Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to redirect a directory to another directory but I've hit a snag. I want to redirect /directory_name to /new_directory_name so I put this in my .htaccess:

RedirectMatch 301 /directory_name/(.*) /new_directory_name/$1

Which worked fine BUT I also have another directory called :

/images/directory_name/

And the redirect is redirecting links to files in that directory to /new_directory_name/ and resulting in broken image links.

So I need a redirect that ONLY redirects /directory_name/ and not any other directories that happen to have the same name (but are in a different location).

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I don't know much about the subject, but I tried the following code on my server and it worked. Check it out.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^a\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.a\.com$
RewriteRule ^directory_a\/$ "http\:\/\/a\.com\/new_directory_a" [R=301,L]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.