#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    129
    Rep Power
    11

    Mod rewrite question


    I know this really isn't php but since mod rewrite is used quite a bit to clean up url's that contain php variables I figured this would probably be the best place to post this question.

    I am trying to add a named anchor to the end of my url and get a mod rewrite statement to work with or without that named anchor listed.

    Here is what I have now.

    Code:
    RewriteRule ^faculty/([^/\.]+)/?$ faculty/index.php?pos=$1 [L]
    this changes mydomain.com/faculty/?pos=admin
    into mydomain.com/faculty/admin/

    This page shows every faculty member that is an admin. I have other pages that I want to link to a certain faculty member. So instead of having a new page that only shows a specific faculty member I have added named anchors down the page so that I can link to there.

    So i figured this might do the trick but it doesn't seem to be working


    Code:
    RewriteRule ^faculty/([^/\.]+)/?([^/\.]+)/?$ faculty/index.php?pos=$1#$2 [L]
    So i want to be able to have.

    mydomain.com/faculty/?pos=admin#bobbarker
    become mydomain.com/faculty/admin/bobbarker


    Any help would be appreciated
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You can't do this because anchors are entirely client side. If the anchor isn't present in the URL the browser will not jump to it.

    However, you could redirect mydomain.com/faculty/admin/bobbarker to mydomain.com/faculty/?pos=admin#bobbarker or mydomain.com/faculty/admin#bobbarker by performing an actual redirect using the R flag.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,953
    Rep Power
    4033
    There is an apache forum, that is where the question should go. I've reported to post to have it moved.

    That said, it may be possible to do what you want, but you would likely have to have the rewrite perform an external redirect to the new URL, rather than it be an internal re-write. The hash component (or anchor) is something that is handled client-side and not relevant on the server.

    Rather than trying to rewrite the hash, you could probably also do a url like this:

    Code:
    mydomain.com/faculty/admin#bobbarker
    if that is acceptable. Apache would still re-write internally to the ?pos=admin url and then the client would process the hash when the page is loaded.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    129
    Rep Power
    11
    Thanks for the responses and sorry for not putting this in the right location. I have never noticed the apache forum before.

    This is what I have come up with now. This works for me because I basically just needed for the faculty members to give out a user friendly url. while the actual url it redirects too is not that important

    So using this

    Code:
    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)$ /jhhs/faculty/$1#$2 [NE,R,L]
    works for me.

    Thanks Again

IMN logo majestic logo threadwatch logo seochat tools logo