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]
  • Joel: see the RewriteCond I added. Commented Nov 15, 2010 at 10:35

1 Answer 1


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]
  • This causes an infinite loop.:
    – Joel
    Commented Nov 15, 2010 at 8:16
  • When trying RewriteRule ^contact-us contactUS.php [NC,L] , RewriteRule ^contactUS.php contact-us [NC,R=301]
    – Joel
    Commented Nov 15, 2010 at 8:17
  • A redirect is not the same as a rewrite... This will not cause an infinite loop. Commented Nov 15, 2010 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
    Commented Nov 15, 2010 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.