3

I need to replace /xyz with /index.html?dh=xyz. I use the following config in httpd.conf:

RewriteCond %{QUERY_STRING} "!dh"
RewriteRule "^/(.*)$" "/index.html?dh=$1" [R]

This works perfectly if [R] flag is present, but if I remove it, the query string is missing from the resulting URL. I would like to use the internal rewrite (no [R]). Any ideas?

3
  • Your code looks as if it should work, although you'd probably want/need to use the L flag. Do you have any other directives (mod_rewrite, mod_alias)?
    – MrWhite
    Commented Apr 10, 2016 at 8:43
  • "the query string is missing from the resulting URL" - how / where are you reading the query string (URL parameters)?
    – MrWhite
    Commented Apr 10, 2016 at 18:10
  • I don't have any other rewrites or aliases, therefore I have no L flag. Here is the entire index.html: <script> console.log(self.location); </script>
    – TomasJ
    Commented Apr 10, 2016 at 20:06

1 Answer 1

1

Here is the entire index.html: <script> console.log(self.location); </script>

Well, that's the problem. You won't be able to see the rewritten URL (and query string) from client-side JavaScript.

An internal rewrite is entirely internal to the server. JavaScript only sees the initial URL of the request - the URL displayed in the browsers address bar. eg. /xyz.

1
  • If this answered your question, then please mark it as accepted (green tick on the left) to remove it from the unanswered question queue. You can also upvote (click on "up arrow") answers that you find useful. Thanks.
    – MrWhite
    Commented Apr 11, 2016 at 7:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.