I have a problem with links generated by php, for example this link works:


but when that is opened in the browser it is turned into this link:


Now, I have sent this link to other people but it does not open the page I want it to show. So my question are:

  1. Why is the browser doing this re-interpretation of the url?

  2. I try to catch the URL that is not working with .htaccess but I can't catch (but I can catch the url that is working) - what is happening?

  • Characters in links will be encoded by the browser when sent to the web server. If you have encoding in your link already, that encoding will be encoded with the risk of making the link invalid. Remove the encoding from your original link and you should be fine. Make sure to use valid characters in your links. – closetnoc Jul 3 '15 at 15:21
  • hi, thanks, does that explain why i cannot catch the wrong link with htaccess as well? because it is fundamentally not a link? for example this link "/Thema_Analyse%20und%20Darstellung%20der%20%C3%B6kologischen%20Vorteile%20des%0ARemanufacturings%20f%C3%BCr%20die%20Corporate%20Responsibility%20Strategie%20und%20Marketing%20anhand%20eines%0ABeispielprodukts-3966.html" I just cannot grab with htaccess – StnBnu Jul 3 '15 at 15:46
  • I would start by fixing the link. Once you have it working as you expect, edit into your question any .htaccess rules you have so that we can figure that out too. If your .htaccess rules are trying to fix your problem, then you can simply delete it or comment it out. – closetnoc Jul 3 '15 at 15:52
  • @closetnoc But the link already looks "fixed" to me? And the above link works (as stated). "Remove the encoding from your original link" - why? I assume you mean "percent encoding"? At first I thought this might be a character-set encoding issue, but I can't see the problem looking at the string(URL) in a hex editor. The browser appears to be converting the hyphens (%2D) in the URL-path into spaces (%20), yet the hyphens are perfectly valid in the URL-path unencoded. (?) – MrWhite Jul 3 '15 at 16:14
  • 2
    The browser is not changing the URL, a script on your site is doing that. If you disable javascript and load your page, the URL does not change. Hopefully that will at least point you in the right direction. – Tim Fountain Jul 3 '15 at 16:29

Starting on line 322 of your custom.js file you have this code as part of the carousel render:

var u=window.location.pathname;

The code is not especially clear, but it seems to be building a URL by encoding a "question" string (presumably this 'question' can contain spaces). It's then setting the URL to that (window.history.replaceState) if a condition fails. I guess this is what is causing the URL change you're seeing.

  • Probably not directly related to this problem, but encodeURIComponent() is also the wrong function to use in this instance. It should be encodeURI(). – MrWhite Jul 3 '15 at 18:46

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.