Jump to content

[SOLVED] mod_rewrite with # in regex pattern


lazylester

Recommended Posts

I'm using mod_rewrite to manipulate requests that look like this: www.mydomain.com/myfile.html#someanchor

 

I would like the anchor name ("someanchor") to appear as a $_GET parameter, so rewrite the filename to myfile.html?anchor=someanchor

 

However the mod_rewrite regex pattern seems to fail with the #.  I've tried my regex expressions on other regex engines (e.g. php) and it finds the pattern, but in mod_rewrite, the # seems to terminate the pattern search. For example, if I request the file myfile.htmlmyanch#or to this:

 

          RewriteRule ^(.*).html([a-z#]*) test.html\?position=$2

 

the variable in $2 is "myanch" (even if I escape the # in the regex pattern, which I don't believe is necessary, but tried anyway)

 

Can anyone shed any light on this, please? thanks in advance

 

Les

 

Link to comment
Share on other sites

I've learned that the "fragment identifier" appended to a URI with the "#" prefix, is not sent to the server by the browser. Instead it is retained by the browser and used to navigate to a reference within the returned document when the server responds.

 

That's why I couldn't match it with the mod_rewrite regex.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.