Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In my website I changed or better word modified the directory name ""vehicles-cars"" to ""vehicles-cars-for-sale"" when i tried to redirect using wild card redirect my old directory name to new directory name in my web hosting cpanel account. every time when i open pages from that directory i am getting error code.

This web-page has a redirect loop.

The website is php.

The problem is that that my lots of pages from old directory are indexed in googles and they are getting duplicate contents.

If I redirect single page it works perfect but there are lots of pages so I need wild card redirect to redirect whole directory .

I really need some advice what to do with this problem.

Here is .htaccess file code for redirect thanks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$

RewriteRule ^vehicles\-cars\/?(.*)$ "http\:\/\/example\.com\/vehicles\-cars\-for\-sale\/$1" [R=301,L]

i have other wilcard redirect of whole directory with same code and its working perfect here is the code in .htaccss file which is same as above and working perfect for this directory

RewriteCond %{HTTP_HOST} ^adsbuz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.adsbuz\.com$
RewriteRule ^autos\/?(.*)$ "http\:\/\/adsbuz\.com\/vehicles\-cars\-for\-sale\/$1" [R=301,L]

so i dont understand whats wrong with the above code please i really need some expert advice thanks again

share|improve this question

1 Answer 1

^vehicles\-cars/?(.*)$ will match: /vehicles-cars-for-sale/ causing your loop.

I'd start by removing the optional operator for the trailing /:

RewriteRule ^vehicles\-cars/(.*)$ ....

and add another one to deal with the one URL that wouldn't match:

RewriteRule ^vehicles\-cars$ ...

This -should- work; I haven't tested it:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$

RewriteRule ^vehicles\-cars/(.*)$ http://example\.com\/vehicles\-cars\-for\-sale/$1 [R=301,L]
RewriteRule ^vehicles\-cars$ http://example\.com\/vehicles\-cars\-for\-sale/ [R=301,L]
share|improve this answer
sir i really appreciate your resposec is what that you exactly recomend see the code below please – david Sep 6 '12 at 20:01
I uh, don't see any code :o – thinice Sep 6 '12 at 20:18
sir i really appreciate your respective response but here you are recommending one with / and another out with out / if you don't mind and have time please do me a favor write the whole .htaccess code to redirect my directory as above thanks i hope you don't mind – david Sep 6 '12 at 20:38
Politeness goes a long way ;) – thinice Sep 6 '12 at 21:11
sir i am really sorry for that – david Sep 6 '12 at 21:25

Your Answer


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.