I have organized my huge .htaccess file by Redirect permanent first which I would like to have executed if found. In those case, I don't want later mod_rewrite processed.

Is there any way to achieve that?


Redirect permanent /products/example.aspx http://www.example.com/products/example/

RewriteCond %{REQUEST_URI} products/([1-9a-zA-Z\s-]+)/
RewriteRule ^products/([0-9a-zA-Z\s-]+)/tutorials(/|\.php)$ /products/$1/help/ [R=permanent,L]

While above does not conflict, my .htaccess file is 60k large, and there are some simple "Redirect permanent" that seems to be ignored because a later RewriteRules (that e.g. redirects a pattern instead)

  • 1
    Could you show us a few example (not your whole file) of your Redirect permanent and mod_rewrite rules?
    – Læti
    Mar 11 '13 at 22:51
  • Tonin: Are you asking because Redirect permanent should already take precedence by default?
    – Tom
    Mar 12 '13 at 10:30

Putting "Redirect" statements before "RewriteRule" in a .htaccess file does not mean they get executed first. RewriteRules get executed before Redirect and Alias directives. They are handled by different modules, and mod_rewrite gets called first. For this reason I sometimes use a rewrite to short circuit all alias and redirect statements.

I would suggest not to mix redirects and rewrites, and to convert your redirects to rewrites and add them to the head of your list or rewrites.

  • Thanks. I had hoped for a way to override behavior on what got processed first. But I will be changing them all to rewriterules over time then :)
    – Tom
    Mar 12 '13 at 11:00
  • 1
    Could you provide a source for the mod order?
    – robsch
    Jun 29 '15 at 8:20

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.