However, when I test out my htaccess using the following code, the second one doesn’t work. Is there a way to do an IF statement so that it properly detects if a number or word is in the URL?
I think my final rule should be replaced with the following:
RewriteRule ^(.*)$ index.php?sponsorUsername=$1 [L]
# or even more strict and prevents any directories
RewriteRule ^(.+)$ index.php?sponsorUsername=$1 [L]
Thanks for your speedy response John! Could you take it a step further and elaborate what your code is doing? I’m still a newbie when it comes to ModRewrite.
And how does your code accommodate a number or a name when, in the end, it appends the value to the sponsorUsername? In the code I have been using, the index.php?x=$1 refers to a number.
My knowledge is limited on the subject but I will try and look forward to being corrected by some knowledgeable members.
### command to implement RewriteCondition AND RewriteRule
RewriteEngine on
### reads command line and interprets as a file
RewriteCond %{REQUEST_FILENAME} !-f
### reads command line and interprets as a directory
RewriteCond %{REQUEST_FILENAME} !-d
### interpret, execute and route RewriteCond to specific root file including directories
RewriteRule ^(.*)$ index.php/$1 [L]
### interpret, execute and route RewriteCond to specific root file excluding directories
RewriteRule ^(.+)$ index.php?sponsorUsername=$1 [L]
The code specified allows everything and nothing to be passed to the index.php sponsorUsername parameter.
I find it far easier to use PHP to test or eliminate prohibited characters.
If the desired request exists the response is routed and activated, If it does not exist then an attempt is made to search and route to a nearest match otherwise fall through to a final 404,php file.
Mitt is quite correct about the DANGER of using the EVERYTHING (or NOTHING) atom but J_B correctly provided an exit to the loop ^(.*)$ normally causes.
That said, it seem as if the OP is asking to upgrade [0-9]+ to [a-z]*[0-9]+ (translation: one or more digits to ZERO or more lowercase letters followed by at least one digit). As usual, better specification of the acceptable x or SponsorUserName would get a better answer.
Finally, if the OP really wants to learn about coding mod_rewrite (with plenty of examples), http://dk.co.nz/seo. It’s helped MANY members over the years and should help here, too.