views:

412

answers:

4

Hello,

I want to be able to redirect the user when they type in http://example.com/user/user-name to http://example.com/user/user-name, which displays user details

This is what I am using but it gives me errors

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^.*$ /user/ [R]

The error which firefox gives is

Redirect Loop

Firefox has detected that the server is redirecting the request for this address in a way that will never complete. The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.

  • Have you disabled or blocked cookies required by this site?
  • NOTE: If accepting the site's cookies does not resolve the problem, it is likely a server configuration issue and not your computer.

Thanks

+1  A: 

are those two urls not the same?

Edit: when i replied, the question only stated the need, not the error

adam
adam, I actually am confused
+4  A: 

You indeed have a redirect loop. You are trying to go from domain.com/user/user-name to domain.com/user/user-name (the SAME URL). What happens is:

  1. User accesses domain.com/user/user-name.
  2. User is redirected to domain.com/user/user-name (the same location).
  3. User is redirected again to domain.com/user/user-name (the same location).
  4. User is redirected again to domain.com/user/user-name (the same location).
  5. Repeat ad nauseum...

Perhaps you meant to redirect domain.com/user/user-name to domain.com/users.php?u=user or something?

lc
+3  A: 

You're redirecting everything to /user/ including itself.

Edit: Every request runs through the same set of rewrites, and since your regex of ^.*$ matches you'll redirect /user/ to /user/ again. The browser is just helping you out by stopping the loop after a few attempts on the same URL.

If you're looking to redirect /a/foo to /b/foo, you need something like:

RewriteRule ^/a/(.*)$ /b/$1 [R]

..but you need to have the source and destination not overlap as in your initial example, or you'll get an infinite redirect loop.

Legooolas
yes and in the root there is a index.php file which will display the required content
+1  A: 

As the others already said, the RewriteRule matches any URI path (including /user/) and thus lead into an infinite loop.

To avoid this you have to exclude this URI path:

# either
RewriteRule !^/user/$ /user/ [R]
# or
RewriteCond %{REQUEST_URI} !^/user/$
RewriteRule ^ /user/ [R]

These rules redirect every URI path that is not matched by ^/user/$ to /user/. If you want to use this rule in a .htaccess file, you have to remove the leading slash in the pattern of the RewriteRule directive (so just ^user/$).

Gumbo