Slight .htaccess Problem

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

Slight .htaccess Problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
influx
Forum Commoner
Posts: 31
Joined: Fri Aug 05, 2005 9:28 am

Post 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!
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Code: Select all

RewriteEngine On

RewriteRule ^([a-z0-9_\-]+)(/)?$ redirect.php?user=$1
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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.
Post Reply