Page 1 of 1

Slight .htaccess Problem

Posted: Wed Feb 01, 2006 11:24 am
by influx
I have the following code in my .htaccess file for my website.

Code: Select all

RewriteEngine on
RewriteBase /
RewriteRule ^([A-Za-z_0-9-]+)((/)|())$ redirect.php?user=$1
Now let me explain. I basically host a blog site for a few friends of mine and I make it possible for users to view their blog by visiting http://www.website.com/username instead of having to go to http://www.website.com/redirect.php?user=username.

The only problem with this is if somebody types in 'www.website.com/username/' instead of 'www.website.com/username' they will get a 404 error.

I seemed to have made some strides with the code, if I enter, for example, 'www.website.com/myusername/' it will redirect me to: http://www.website.com/myusername/redir ... myusername instead of just http://www.website.com/redirect.php?user=myusername

I think I'm really close. How should I modify the .htaccess code to alleviate the problem with the extra slash at the end?

Thanks in advance!

-influx

Posted: Wed Feb 01, 2006 12:16 pm
by pickle
Moved to web servers forum.

This is a rewrite rule in an htaccess file that is supposed to take care of a lack of trailing slashes. I didn't write it, but I know it works.

Code: Select all

RewriteRule ^([^\.]*[^/])$ $1/

Posted: Wed Feb 01, 2006 4:56 pm
by influx
Hey all,

I tried changing it to the following:

RewriteEngine on
RewriteBase /
RewriteRule ^([A-Za-z_0-9-]+)((/)|())?$ redirect.php?user=$1


I even tried adding a / in front of redirect.php to call for the home directory.

None of this seems to work for me. If i type in http://www.website.com/username/ it will still redirect to http://www.website.com/username/redirec ... r=username.

What could be wrong? Could it be my server?
Thanks guys!

Posted: Fri Feb 03, 2006 3:25 pm
by phice

Code: Select all

RewriteEngine On

RewriteRule ^([a-z0-9_\-]+)(/)?$ redirect.php?user=$1

Posted: Wed Feb 08, 2006 2:54 pm
by phice
If this worked for you, please post a reply saying it did so we can label this threat as [SOLVED] to help others.