Titan
Titan

Reputation: 6050

Excluding filename using RewriteRule

I want to pipe all URIs into index.php UNLESS the specific file exists in the root. I'm a little stumped when it comes to excluding index.php from this as of course it won't match my last catch all rule

Options +FollowSymLinks -Indexes
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} != "index/.php" // I'm not sure on the syntax here
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^([^/]*)(.*)$ index.php?category=$1&post=$2 [L,QSA]

Upvotes: 1

Views: 29

Answers (1)

Titan
Titan

Reputation: 6050

Solved by adding additional conditions to the last rule

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)(.*)$ index.php?category=$1&post=$2 [L,QSA]

Upvotes: 1

Related Questions