Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-01-2012, 10:51 PM   PM User | #1
jewishj
New Coder

 
Join Date: Sep 2002
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
jewishj is an unknown quantity at this point
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.
jewishj is offline   Reply With Quote
Old 03-02-2012, 10:50 AM   PM User | #2
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
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.
leslie.jones is offline   Reply With Quote
Old 03-03-2012, 04:04 AM   PM User | #3
jewishj
New Coder

 
Join Date: Sep 2002
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
jewishj is an unknown quantity at this point
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.
jewishj is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:16 PM.


Advertisement
Log in to turn off these ads.