Hi.
I've been working on this for maybe 10 hours without success and hope someone can help me here.

Sounds simple:

I want the user to enter URLs similar to this:
www.site.com/thisuser
or
www.site.com/thisuser/
(never underestimate the stupidity of the user, so I want it to work with or without the last slash)

The folder /thisuser/ (or whatever else is entered) does not exist.

This should redirect the user to:
www.site.com/users/index.php?id=thisuser

And for some reason I can't get it to work. All I get is either Firefox or Error 500 telling me about redirecting loops.

I keep seeing this version here that should work, but for some stupid reason it just won't for me:

#Options +FollowSymlinks
Options +FollowSymLinks -MultiViews
# // found -MultiViews somewhere and tried it without success
RewriteEngine on

#RewriteCond %{SCRIPT_FILENAME} !-f
#RewriteCond %{SCRIPT_FILENAME} !-d
# // for testing purposes, I simply disabled these for now to make sure it is the next line that does the work:

RewriteRule ^([^/]+)/?$ /testredirect.php?$1 [QSA,L]

# //used /testredirect.php for now to see if it would work - tried /test/$1 before, also without success

According to one or two different forum posts I found, this should be exactly the code I want.

Why does it create these loops?

Any idea on what I can do?

Thanks so much in advance!

Recommended Answers

All 5 Replies

Does this .htaccess apply to the root of your domain also?

Maybe try a full URL.

Hi, thanks for the reply.

The .htaccess file is in the root folder, if that is what you're asking.

Where should the full URL go?

Here?

RewriteRule ^([^/]+)/?$ http://testsrv/testredirect.php?$1 [QSA,L]

(I'm running it on my test server right now in case there's any confusion about the "domain").

Yes, there.

But if you put it in your main folder, then the rewrite rule matches /testredirect.php aswell, won't it ?;)

Ah, good point...
So I need to exclude that file (or later on folder) from that...

So, would this do the trick (if added before the other code)?

RewriteRule ^(testredirect.php)(/.*)?$ - [L]

Never mind, I just tried it, and it seems to work!!!!!!!!

W00h00!!! :-)

Thanks so much!

Ah, good point...
So I need to exclude that file (or later on folder) from that...

So, would this do the trick (if added before the other code)?

RewriteRule ^(testredirect.php)(/.*)?$ - [L]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.