Mod_Rewrite Help

The only URL I want to be affected by this Rewrite is “user.php”. Could I use a RewriteCond to make that happen?

You said you want the URLs to be http://localhost/social/USERNAME

there is no user.php in that URL

Yhea. I just finished testing that. This is challenging.

This is my new code.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_URL} !\\.php
RewriteRule ^/?social/([^/]+)$ social/user.php?user=$1 [NC,L]

The same problem occurs (“user.php” being the only thing shown on all pages). Is there a way so if a file name or nothing is typed, that it will Not rewrite?

Thanks for all your help!

These will exclude requests that correspond to actual files or directories:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

What problem you’re having isn’t clear to me. If the text “user.php” is literally appearing in the browser content area when you type /social/something, then that’s a problem with whatever user.php does, not with the rewrite rule.

YES! That solved! Thank you Dan and thanks you DK! :bouncy2:

BM,

Ah, LOGIC! It can be so challenging at times!

First, thanks Dan for covering while I took a badly needed nap!

Second, congratulations, BM, for giving it a good try and getting to an answer (with Dan’s help).

Finally, it seems to me that you merely want to change the username to be the value of the user in a query string. That would mean (as I’d suggested above) one of the following:

RewriteCond %{QUERY_STRING} !user=
RewriteRule ^social/([a-zA-Z]+)$ social/user.php?user=$1 [L]
# Where you got tripped up was trying to use the value of the {QUERY_STRING} when there was none!

# OR

RewriteCond %{REQUEST_URI} !user\\.php
RewriteRule ^social/([^/.]+)$ social/user.php?user=$1 [L]
# This wouldn't loop because I added the dot character to the rule's regex to exclude filenames (with extensions)

# OR Dan's solution to exclude existing files

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

Regards,

DK