Take the 2-minute tour ×

How can I get anything but files to rewrite to index.php's params? I'm using apache, mod_rewrite, etc.

share|improve this question
I think you need to be more specific. Are the params in a regular query string format (?a=1&b=2 ...) or a fake folder structure (/a/1/b/2) or something else? What's the base url of the query string? domain.ext/query or something else? –  Tom Smilack Sep 18 '10 at 4:33
add comment

2 Answers

up vote 5 down vote accepted

If you want to rewrite anything that isn't a request for a regular file I'd use this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/index\.php -f
    RewriteRule ^(.*)$  /index.php?page=$1 [QSA]

This way you don't need to concern yourself about adhering to a certain URL format for your rewrites - you can test and act accordingly in your serving script.

share|improve this answer
add comment

Try this:

RewriteRule /([^/]*)/([^/]*)/([^/]*)[^\.].*  /index.php?var1=$1&var2=$2&var3=$3 [R=301]

This will redirect url like /foo/bar/baz to /index.php?var1=foo&var2=bar&var3=baz

share|improve this answer
add comment

Your Answer


