RewriteEngine on
RewriteRule ^/social/([^/]+)$ /user.php?user=$1
When I type “http://localhost/social/USERNAME” I get a “Not Found” error message saying “The requested URL /social/USERNAME was not found on this server.” instead of sending me to “http://localhost/social/user.php?user=USERNAME” I dont’ know what the error is and I am new to mod_rewrite. Could somebody help me, or tell me my error?
Moreover, BMorganVA, if your .htaccess file is located in the social directory, it will NEVER see ^/social/{yadda-yadda}! Basically, it cannot see the directory it’s in.
Next, if you move this mod_rewrite code to the DocumentRoot (as Dan inferred), then Apache 2.x would choke on the leading / (Apache 1.x would REQUIRE it). Since you didn’t mention which flavor you’re using, then use ^/? which satisfied both cases.
BTW, incorporating the <IfModule> braces means that the test is made for EVERY request - a TOTAL WASTE of server resources and a KILLER on a shared host! It’s there because the WP people don’t want their code to give the clueless masses an Error 500 because they don’t have mod_rewrite enabled.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^social/([^/]+)$ social/user.php?user=$1 [L]
The error message (in Firefox) says, “Firefox has detected that the server is redirecting the request for this address in a way that will never complete.” 500 error shows up when the second part of the rule starts with / and the URL can’t be found if it starts with “^” or “^/”.
Can anybody help please? Thanks so much. If I didn’t already say this, this will help my site a lot!
Since you’re new to regex, you may not recognize that ([^/]+) is the same thing as (.*) but excluding the / character. Saying that, you should recognize that user.php IS MATCHED, i.e., YOU are driving the server LOOPY. You can avoid this by using a RewriteCond which either looks for the user key in the {QUERY_STRING} OR merely excluding user.php.
Moreover, RewriteBase is to be used to UNDO mod_alias redirects so that, if this is your entire .htaccess file, it has NO BUSINESS in your directives.
I’m trying to find out how do get the condition that you suggested. Could you, or somebody else please show and example? I’m trying to learn from this page, but it’s not that helpful. Thanks!
One more thing, does the RewriteCond go before or after the rule?
Did you look at the TUTORIAL linked in my signature for code?
WARNING! I treat those asking for me to code for free as “script kiddies.” I’m here to help you LEARN but get upset at those asking me to code for them. Just minimal effort on member’s part will gain a LOT of help from me!
I’m getting that same error message that I was before, and the message shows up on all pages.
I do have a few questions. First, in {QUERY_STRING} do I enter my own value or not? Second, I can’t figure out how to grab the user name out of the {QUERY_STRING} (if it is even contained in that variable). Finally, I don’t know how to get rid of the “user.php” part and I don’t know what DK means by “excluding it”. I’m not asking for an entire scrpit, I’m just asking for general answers. This is my first time using mod_rewrite.
is a URL with no query string at all, so it doesn’t match and the rule isn’t applied
If that’s what your URLs will look like then you do not have a query string and don’t need a RewriteCond to match any query string. You’re creating a query string where there was none, and it’s based on the username in the URL.