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?

  • 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 Apr 10 '16 at 8:43
  • "the query string is missing from the resulting URL" - how / where are you reading the query string (URL parameters)? – MrWhite Apr 10 '16 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 Apr 10 '16 at 20:06
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.

  • 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 Apr 11 '16 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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