December 10th, 2011, 07:59 PM
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.
this changes mydomain.com/faculty/?pos=admin
RewriteRule ^faculty/([^/\.]+)/?$ faculty/index.php?pos=$1 [L]
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
So i want to be able to have.
RewriteRule ^faculty/([^/\.]+)/?([^/\.]+)/?$ faculty/index.php?pos=$1#$2 [L]
Any help would be appreciated
December 10th, 2011, 09:35 PM
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.
December 10th, 2011, 09:49 PM
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:
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 out out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
December 11th, 2011, 01:12 AM
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
works for me.
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)$ /jhhs/faculty/$1#$2 [NE,R,L]