Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I decided to convert all my dynamic pages to static pages URLs. I used to have "/contactUS.php" and now I want the page to be served as "/contact-us".

I used to following rule n .htaccess:

RewriteRule ^contact-us contactUS.php [NC,L]

It all works fine, but the problem is that I want to prevent entrance to "/contactUS.php" to aviod duplicate content. Of course that adding the following rule:

RewriteRule ^contactUS.php contact-us [NC,L]

creates an infinite loop. What is the best way to achieve the goal, also taking SEO into account?


This causes an infinite loop:

RewriteRule ^contact-us contactUS.php [NC,L]
RewriteRule ^contactUS.php contact-us [NC,R=301]
share|improve this question
Joel: see the RewriteCond I added. – Lèse majesté Nov 15 '10 at 10:35
up vote 0 down vote accepted

Re-write contact-us as contactUS.php.

Redirect contactUS.php to contact-us.


Redirects and rewrites are 2 different things. In a redirect, the URL change happens client-side. In a rewrite, the URL change happens entirely server-side. I.e.:


Client: GET /foo
Server: Location: /bar
Client: GET /bar
Server: [/bar]


Client: GET /foo
(Server: /foo --> /bar)
Server: [/bar]

So if you set up the above rewrite and redirect rules, the client will always navigate to /contact-us, while the server will always serve up /contactUS.php.


Sorry, I forgot to mention that mod_rewrite applies rewrite rules to internal requests as well as client requests. So you need to add a rewrite condition to the redirect to prevent this:

RewriteRule ^contact-us$ contactUS.php [L]
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteRule ^contactUS.php$ contact-us [R=301]
share|improve this answer
This causes an infinite loop.: – Joel Nov 15 '10 at 8:16
When trying RewriteRule ^contact-us contactUS.php [NC,L] , RewriteRule ^contactUS.php contact-us [NC,R=301] – Joel Nov 15 '10 at 8:17
A redirect is not the same as a rewrite... This will not cause an infinite loop. – Lèse majesté Nov 15 '10 at 8:52
I edited the question with the code that causes the redirection loop (I get "This webpage has a redirect loop." error). What is wrong with that code? – Joel Nov 15 '10 at 8:56

Your Answer


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