is possible to exclude a url being parsed by mod rewrite?
my .htaccess has rewrite rules like
RewriteRule ^contact contact_us.php
and a couple more static pages.
currently my site don’t have troubles cause uses http://domain.com/user.php?user=username
but now i need rewrite to:
http://domain.com/username
I’ve tried with:
RewriteRule ^(.*)$ user.php?user=$1 [L]
but all my site stops working…
is possible to avoid parse my static pages like contact/feed/etc being treated like usernames?
edit to match david req:
this is my actual .htaccess file:
RewriteEngine On
Options +Followsymlinks
RewriteRule ^contact contact_us.php [L]
RewriteRule ^terms terms_of_use.php [L]
RewriteRule ^register register.php [L]
RewriteRule ^login login.php [L]
RewriteRule ^logout logout.php [L]
RewriteRule ^posts/(.*)/(.*) viewupdates.php?username=$1&page=$2
RewriteRule ^post(.*)/([0-9]*)$ viewupdate.php?title=$1&id=$2
RewriteRule ^(.*)$ profile.php?username=$1 [L]
also i’ve enabled modrewrite log my first file:http://pastie.org/1044881
Put the rewrite rules for the static pages first, and add the
[L]flag to them:then after those, use your rewrite rule for the username:
(hopefully nobody has a username of
contact).EDIT: Based on the log output you posted (which I’m assuming corresponds to an unsuccessful attempt to access the
contactpage… right?), try changing thecontactrewrite rule to eitheror
That is, either add
$to make the pattern match only the literal URLcontact, or add theNSflag to keep it from applying to subrequests. According to the log output, what seems to have happened is that Apache rewritescontacttocontact_us.phpand then does an internal subrequest for that new URL. So far so good. The weird thing is that the^contactpattern again matchescontact_us.php, “transforming” it tocontact_us.php, i.e. the same thing, which Apache interprets as a signal that it should ignore the rule entirely. Now, I would think Apache would have the sense to ignore the rule only on the subrequest, but I’m not sure if it’s ignoring the entire rewriting process and leaving the original URL,/contact, as is. If that’s the case, making one of the changes I suggested should fix it.EDIT 2: your rewrite log excerpt reminded me of something: I’d suggest making the rewrite rule
since slashes shouldn’t be occurring in any usernames. (Right?) Or you could do
if usernames can only include word characters (letters, numbers, and underscore). Basically, make a regular expression that matches only any sequence of characters that could be a valid username, but doesn’t match URLs of images or CSS/JS files.