CaymanCarver
CaymanCarver

Reputation: 419

How can I mod_rewrite all incoming URLs except certain specific ones?

I'm trying to rewrite URLs where there are a few fixed page URLs, and everything else gets rewritten. Here's what I need:

domain.com/
domain.com/about
domain.com/* (anything else)    

Should redirect to:

/index.php
/about.php
/display.php?id=*

No idea how to do it. Can anyone help me out?

Upvotes: 0

Views: 36

Answers (1)

CaymanCarver
CaymanCarver

Reputation: 419

Solved! This works:

RewriteRule ^about$ /about.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /display.php?id=$1 [L]

The index page is handled by using (.+) instead of (.*), which lets the site config forward the request normally to index.php so .htaccess doesn't try and forward it to display.php.

Upvotes: 2

Related Questions