2

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?

Examples:

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)

2
  • 1
    Could you show us a few example (not your whole file) of your Redirect permanent and mod_rewrite rules? Commented Mar 11, 2013 at 22:51
  • Tonin: Are you asking because Redirect permanent should already take precedence by default? Commented Mar 12, 2013 at 10:30

1 Answer 1

4

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.

2
  • 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 :) Commented Mar 12, 2013 at 11:00
  • 1
    Could you provide a source for the mod order? Commented Jun 29, 2015 at 8:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.