views:

387

answers:

2

My current .htaccess file

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^falsebase\.net
RewriteRule (.*) http://falsebase.net/$1 [R=301,L]

I want to add on to this so I when a user enters "http://u.falsebase.net/USERNAME" into their address bar they get directed to "http://falsebase.net/profile.php?name=USERNAME".

I imagine this is pretty simple, I just have no experience with .htaccess, and after scanning through about 12 other threads that seemed similar to this, I did not get a consistent answer from any of them.

A: 

Try these rules:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^(u\.)?falsebase\.net
RewriteRule (.*) http://falsebase.net/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(u\.)?falsebase\.net
RewriteRule ^[^/]+$ http://falsebase.net/profile.php?name=$0

Or if an internal redirect is possible:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^(u\.)?falsebase\.net
RewriteRule ^[^/]+$ profile.php?name=$0
Gumbo
A: 

You need to use an internal rewrite rule, not an external redirect. You don't really want your users to ever see an ugly URL like /profile.php?name=USERNAME.

So try using something like

RewriteEngine On
RewriteRule ^/(.+)$ /profile.php?name=$1

where .+ is a pattern that matches the username.

If you know your usernames are all a-z or A-Z characters, for instance, you could tighten this up above by using

RewriteEngine On
RewriteRule ^/(a-zA-Z)$ /profile.php?name=$1

Bear in mind that having the username part of your URL as /username will catch all possible URLs. You might want to put these into a specific namespace, like

http://www.example.com/user/<username>

where is the entered username, in which case you would use

RewriteEngine On
RewriteRule ^/user/(.+)$ /profile.php?name=$1

etc.

fooquency
I tried, this but it doesn't seem to work. I am trying to add something to my current htaccess file (shown above), not replace it with something. I want the htaccess to both redirect all www.mydomain.net -> mydomain.net (it already does this and works fine) and add the internal rewrite so mydomain.net/u/USERNAME always loads the page mydomain.net/profile.php?name=USERNAME, while still having mydomain.net/u/USERNAME appear as the URL.
Roinator
Ok, so I know it's been awhile, but I found it it was my hosting service not reading my .htaccess file. Thanks for your help!
Roinator