DonCroce
DonCroce

Reputation: 475

HTACCESS Rewrite Order

The line with rewriting index.php and the other three lines work perfectly, but not when put together, I've tried all possibilities with position of the lines, and to be honest pretty exhausted.

My code below:

RewriteEngine On
RewriteRule (.*) index.php
RewriteCond %{REQUEST_URI} !^/(admin|admin/.*)$
RewriteCond %{REQUEST_URI} !^/(l|l/.*)$
RewriteCond %{REQUEST_URI} !^/(includes|includes/.*)$

Can anyone help me in this quick question?

The script runs in: http://domain.com/folder/

The .htaccess is also placed in that folder.

The problem is that it rewrites also files in the admin,l and includes folder

Upvotes: 0

Views: 296

Answers (2)

anubhava
anubhava

Reputation: 785631

There are few problems in your Rewrite code:

  1. RewriteCond should come before RewriteRule
  2. Multiple RewriteCond can be combined into 1
  3. You must use L flag to mark last rule

Replace your code with this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(admin|l|includes)(/.*|)$ [NC]
RewriteRule ^ index.php [L]

Upvotes: 0

nhutto
nhutto

Reputation: 163

I think what is happening here is the first RewriteRule (.*) index.php is set to rewrite everything regardless of if they match the other regex for the 3 RewriteCond's I think maybe moving it to the bottom and reformulating the rule to be more specific to your needs.

Upvotes: 1

Related Questions