0

I'm able to redirect

https://my.bank.com/caweb/ptbmc/appInfo

to the maintenance page

https://my.bank.com/maintain.html

cat httpd-ssl.conf

RewriteEngine on
RewriteCond %{QUERY_STRING} /caweb/#/ptbmc
RewriteRule (.*) https://my.bank.com/
RewriteRule ^(/caweb/ptbmc.*)$ /maintain.html [PT]

However, i need to redirect the URL now containing the special character # i.e., https://my.bank.com/caweb/#/ptbmc/appInfo

to the maintenance page

https://my.bank.com/maintain.html

I tried changing RewriteRule to -> RewriteRule ^(/caweb/#/ptbmc.*)$ /maintain.html [NE] but it did not work as well.

Can you please suggest what changes do i have to make in the RewriteRule to get this to work?

3
  • The server never sees the # character. It's only relevant within the browser. Commented Nov 23, 2022 at 13:35
  • @OlafKock but then how can I get the rewrite to work with the URL containing # ? Commented Nov 23, 2022 at 13:44
  • That's my point: You can't (on the server). You'd have to rewrite the HTML that the server generates, but browsers will only send a URL up until (and not including) the # sign. Commented Nov 23, 2022 at 13:59

1 Answer 1

1

From Wikipedia (emphasis mine):

In URIs, a hash mark # introduces the optional fragment near the end of the URL. The generic RFC 3986 syntax for URIs also allows an optional query part introduced by a question mark ?. In URIs with a query and a fragment, the fragment follows the query. Query parts depend on the URI scheme and are evaluated by the server—e.g., http: supports queries unlike ftp:. Fragments depend on the document MIME type and are evaluated by the client (web browser). Clients are not supposed to send URI fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP redirections.

So, as I said in the comment: You can't handle a # sign server side as the condition for a redirect, because the server never sees it. The browser is supposed to not send it.

In this case, if you need any redirect, you'd either need to do it on the browser side (e.g. in Javascript), rewrite the HTML that's generated in the first place, or generate different URLs that don't rely on #.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.