0

I have a .htaccess file with those contents:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/\.]+)$ index.php?string=$1&match=all [L]

So when I type: domain.com/test the page redirects to domain.com/index.php?string=test&match=all

But if I want to reach this page: domain.com/test#sub1

the page redirects to domain.com/index.php?string=test&match=all

instead of domain.com/index.php?string=test#sub1&match=all

How do I proceed?

3
  • 1
    Hashes aren't sent to the server so it sees domain.com/test not domain.com/test#sub1 Commented Nov 19, 2012 at 3:02
  • 1
    The # is only used by the browser, and not sent with the HTTP request. The server never sees it. Commented Nov 19, 2012 at 3:02
  • Indeed, you were just a bit faster :) Commented Nov 19, 2012 at 3:02

1 Answer 1

1

Anchors/hashes are only used by the browser. The server won't see requests for those, because such a request would be invalid. (There is no "test#sub1" file, only a "test" file.) It has no way of knowing you're just wanting to access an anchor and not trying to access a file that doesn't exist, so such information is not passed to the web server.

EDIT: Also, redirecting everything through a single php file just seems like malpractice to me. Maybe there's something special going on here that makes it a reputable approach though.

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

2 Comments

That's the common 'front controller' pattern used by many PHP frameworks.
hmm.. good to know. it just seems odd to me, but then I haven't worked with too many frameworks lately.

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.