Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    301 redirect to remove part of url not working

    Hi,

    This is a slightly uncommon case, but I basically have a site where there are dedicated profile sections for each user and the three distinct types of users.

    So, each user profile page should be accessed by mysite.com/username but people need to be able to go to a url like mysite.com/moderators to see a list of moderators. Something like mysite.com/moderators/username is also valid, but needs to 301 back to the mysite.com/username format.

    So, to recap:

    mysite.com/moderators -> users.php?type=mods
    mysite.com/moderators/username -> mysite.com/username (301)

    What i have is:

    RewriteRule ^moderators|admins|users/(.+)$ /$1 [L,R=301]

    It is failing in two ways:

    1. if they go to mysite.com/moderators this rule is triggered - which it shouldn't be since it uses (.+), so if there is no slash followed by one or more characters, it shouldn't match
    2. if they go to mysite.com/moderators/username - the rule doesn't pass username, and instead redirects to mysite.com/


    Thanks in advance for any help in solving this.

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    1: You are missing a set of braces by the look of it, so the bareword 'moderator' will match. Try: ^(moderators|admins|users)/(.+)$
    2: Fix the above and see what happens.

    Hope that helps.

  • #3
    New Coder
    Join Date
    Sep 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that was my issue. I tried it with square brackets before and it didn't work that way either - I didn't realize I needed the parenthesis.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •