tags:

views:

38

answers:

1

Let's say I want to support urls like twitter where: twitter.com/username redirects to twitter.com/user_name.php?user=username

I have the following

RewriteRule ^(.*)$ user_name.php?user=$1

And that works fine. But the problem is now that everything, including twitter.com/index.php will of course redirect to user_name.php

How can I either create exceptions or precedence so that "real files" don't get rewritten? I tried adding an explicit rule for index.php before and after that one, but it doesn't seem to take effect.

+1  A: 

You need to add RewriteCond for this

RewriteCond %{REQUEST_URI} !-f [OR] # for existing files 
RewriteCond %{REQUEST_URI} !-d # for existing directories
RewriteRule ^(.*)$ user_name.php?user=$1
Eimantas
Okay, that's MUCH better then my solution -- assuming it works. I've got to try that on a project I have. Could you explain what's actually going on here?
Erik
That doesn't work for me, domain.com/index.php still uses the rewrite rule for user_name.php
ry0ohki
Actually you were pretty close, this works for me: RewriteCond %{REQUEST_FILENAME} !-f
ry0ohki
I'm glad you worked that out by your self ,)
Eimantas
Are you sure you want that disjunction? That means only one of the conditions must be fulfilled.
Gumbo