Home > Blockchain >  .htaccess RewriteRule based on anchors
.htaccess RewriteRule based on anchors

Time:12-30

I am trying to update a RewriteRule. Previously, the redirect looked like this:

https://mywebsite.com/docs/#/en/introductionhttps://manual.mywebsite.com/#/en/introduction

I would like to use /docs/ for something else now but I would like to keep redirecting requests containing a forward slash after the # to the manual subdomain. This is what I would like to achieve:

The old redirects continue working as usual: https://mywebsite.com/docs/#/en/introductionhttps://manual.mywebsite.com/#/en/introduction

This would not get redirected since there is no forward slash following the #: https://mywebsite.com/docs/#overview

Here is what I have:

The .htaccess file containing the following existing rule which redirects everything: RewriteRule ^docs/(.*) https://manual.mywebsite.com/$1 [L,R=301]

I tried this but it did not work (I tried with https://htaccess.madewithlove.com/ which says that my rule does not match the URL I entered):

RewriteRule ^docs/#/(.*) https://manual.mywebsite.com/#/$1 [L,R=301]

I also read about the NE (no escape) flag (https://httpd.apache.org/docs/2.2/rewrite/advanced.html#redirectanchors) which did not help either.

I am also sure that the server is actually using the file.

To summarize, my problem is that I want to match a URL containing /docs/#/ and redirect it to a subdomain, keeping the /#/ and everything that follows it.

CodePudding user response:

Anchors are not part of the URL that's transmitted to the server: They stay within the browser, thus you can't build a rewrite rule that take anchors into account.

Inspect your access-logs to see what you get

  • Related