In my website I have some pages that are reachable by two urls:

  • .../page
  • .../parameter/page

In order to optimize the website for the search engines, I have to redirect all .../page urls to .../parameter/page urls.

How can I reach that modifying the file .htaccess?

1 Answer 1


In order to have the redirect perform with the desired behavior, implement a rewrite rule similar to the one included below:

RewriteEngine On
RewriteCond %{REQUEST_URI} !(/(special|cases|which|should|be|excluded)/) [NC]
RewriteRule /(.*) http://www.example.com/parameter/$1 [L,R=301]

A solution to the more specific problem mentioned in the comments (i.e., redirecting all pages that do not have a specific context to use the 'en' context) would be something similar to the following rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} !(/(en|it|de|fr)/) [NC]
RewriteRule /(.*) http://www.example.com/en/$1 [L,R=301]

Note that any additional language directories which the rewrite rule should not apply to will need to be added to the escape clause in the RewriteCond.

Additionally, once this has been put in place, a graceful will need to be issued on Apache in order to pick up the changes.

  • Thank you very much for your answer. But "page" means every page without a parameter. In this case, parameters are language acronims (en,it,de,fr,...). I don't know if now I've been very clear. Jan 1, 2013 at 20:49
  • Maybe I have not been accurate. I'm sorry, I would create a more general post, useful to other cases. Here are my particular needs: I have a multilanguage website and the default language pages are reachable with "domain/page" and also "domain/en/page". The pages in the other languages are reachable just through the language folder ("domain/de/page"). So I want that every "domain/page" redirect to the respective "domain/en/page". Jan 1, 2013 at 21:04
  • No worries -- thanks for the additional information. Just to clarify, do you only want the domain/page combinations to redirect only to the 'en' context (e.g., /info -> /en/info, /about -> /en/about, etc.)? If so, I'll update the answer to reflect this behavior. Jan 1, 2013 at 23:25
  • Yes, exactly! Of course I have pages in other languages (/it/info, /it/about, /de/info, /de/about, etc) that don't have to be touched by the rules. Jan 2, 2013 at 11:54
  • The answer has been updated to reflect both the general case and your specific scenario. Jan 2, 2013 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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