Dissident Rage
Dissident Rage

Reputation: 2716

Apache & mod_rewrite - index not found

This works as desired, except that index or anything in an 'index directory' such as index/foo will fail.

RewriteEngine on

# base dir
RewriteBase /project/

# allow assets/ directory
RewriteRule ^(assets)/(.*)$ $0 [L]

# direct all else to index.php
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]

I've attempted this, but it still does not catch it:

RewriteRule ^index(/.*)?$ index.php/$1?%{QUERY_STRING} [L]

Upvotes: 1

Views: 155

Answers (1)

anubhava
anubhava

Reputation: 785286

Try this code:

Options -MultiViews
RewriteEngine on
# base dir
RewriteBase /project/

# allow assets/ directory
RewriteRule ^(assets)/(.*)$ $0 [L]

# direct all else to index.php
RewriteRule ^((?!index\.php$).*)$ index.php/$1 [L,NC]

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Upvotes: 1

Related Questions