Jared Joke
Jared Joke

Reputation: 1356

Regex for matching a pattern at the end of a URL

I have a really weird pattern that sometimes shows up at the end of urls and I'm trying to write an apache rewrite rule to get rid of it.

Meaning, I'm trying to formulate a regex expression to match anything ending with that pattern So I might have something like

mysite.com/blah#_=_

And I want to match that pattern after blah but I think I either need to escape it or do something. I currently have these sets of rules, well, really loosely laid out

RewriteEngine on
RewriteCond %{HTTP_HOST} regex-goes-here [NC]
RewriteRule ^/(.*) replace-with-url-minus-pattern [R]

Upvotes: 0

Views: 266

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You can't use mod_rewrite or anything on the server's end for to get rid of that. The stuff starting with the # is called a URL Fragment, and it's something browsers (and javascript and other stuff that's client side) use to determine how to display or render content, or used by scripts to pass bits of data between each other. The #_=_ portion of the URI is never even sent to the server.

You'll need to do something on the browser's end, maybe something like this: Remove fragment in URL with JavaScript w/out causing page reload

Upvotes: 1

Related Questions