Nick
Nick

Reputation: 14283

regex - Match # part of the url on the server

I'm trying to write a regex to match parts of urls and use a SEO redirection wordpress plugin to create a 301 redirect on the matching results.

if, for example, I write these URLs:

https://www.test.com/my-site
https://www.test.com/my-site/

I want to be redirect to:

https://www.test.com/your-site/

but if the urls are followed by an hash (#) like the one below:

https://www.test.com/my-site/#/..

Do not redirect.

I have played around for a bit with regExr and this is as far as I could get:

regexr.com/3scpb

But when try to implement it inside the plugin the redirect doesn't work.

What am i doing wrong here? Is it better to do it straight inside the .htaccess file? would it be better and more robust/reliable that way?

Thanks

Upvotes: 1

Views: 45

Answers (1)

Rainb
Rainb

Reputation: 2465

The hash is never sent by the browser.

The hash is used internally by the browser to see which fragment of the document is focused on. This is called fragment identifier. This means your server will never see the # coming up. You cannot prevent this behavior.

Upvotes: 1

Related Questions