Discourse in subdirectory auto-rewrites URLs pointing to other areas of the domain


(Magnetidog) #1

Hi - I have Discourse setup in a subdirectory - mywebsite.com -&nbspThis website is for sale! -&nbspmywebsite Resources and Information.

When I enter URLs pointing to a directory parallel to that one, e.g. mywebsite.com -&nbspThis website is for sale! -&nbspmywebsite Resources and Information., Discourse rewrites the URL as mywebsite.com -&nbspThis website is for sale! -&nbspmywebsite Resources and Information.. Is there a way to prevent this?

Thanks.


(Dean Taylor) #2

Only the traffic to the /community path should be getting to Discourse, if this is occurring you need to fix your proxy / traffic forwarder in front of your sites (main site and Discourse site).

This doesn’t sound like a problem with Discourse.


(Magnetidog) #3

Hi Dean - if I enter the URL in the browser, the url is not redirected.

Anyhow, if I add the uRL to the navigation bar and then click on it, it is loaded asynchronously at the wrong URL location.


(Dean Taylor) #4

Do you have another non-discourse site you are also running on the same machine?


(Magnetidog) #5

Hi Dean - yes, a Wordpress-based website. There is no URL redirection problem elsewhere. It is only when I place URLs in the header of discourse that I see this happening.

I am trying to understand what is triggering this behavior.


(Dean Taylor) #6

I think I understand, can you confirm…

  • You have a Discourse install on “/community
  • You have a link added via a theme customisation that points to /blog in the header
  • Clicking the “/blog” custom link in the header redirects to “/community
  • Navigating directly to “/blog” by typing into the browser navigation bar correctly goes to “/blog

If all of these are true then it will be the Discourse JavaScript taking control of the link…

Do you have any plugins installed?


(Magnetidog) #7

Hi Dean, that is correct.

To be precise, Clicking on the “/blog” custom link in the header redirects to “/community/blog”. This happens only when the URL points to the local domain, not to an external domain, in which case the URL works normally.

I have only the discourse-details, poll, and lazy youtube plugins installed, updated to the latest version.

Yes, I am pretty sure the issue is in the Javascript taking control of the link - I will update if I have more information.


(Dean Taylor) #8

If you right-click on the link and select “Copy link address” what is the link when you paste it?


(Magnetidog) #9

The correct one! And also checking the code via firebug shows the correct URL. The net panel in firebug shows no redirection either, just the wrong resource being loaded.

Which is why I am sure it must be Discourse doing the rewriting via JS.


(Jay Pfaffman) #10

Yes. That’s because Discourse doesn’t go through the external Nginx to do requests. If you want to link to those pages and have them not break, I think you would need to have another domain that redirected back to your domain to escape Discourse hijacking those URLs.


(Dean Taylor) #11

This is where I haven’t done that much playing with sub-directory installs.

It does sound like there is a case where Discourse is picking up on this link in the header and “managing” it.

There may be some case where this shouldn’t be happening at-all i.e. a feature request to get Discourse not to handle any URL’s other than those on the /community base path for sub-directory installs

You could probably work around this by adding some JavaScript:

<a href="http://www.example.com/blog" onclick="document.location.href='http://www.example.com/blog'; return false;">Some link</a>

But this won’t cover the case where your /blog link exists within post content.


(Magnetidog) #12

Thanks so much guys, I will figure out a way - I would have never thought this was an edge case scenario as I saw many Discourses on subdirectories. But now, visiting these other Discourse installations, I cannot find any linking in the way I am doing in the header - this must be the reason.


(Magnetidog) #13

Sorry to bump this - does anybody know if there was a change in the codebase to address the issue?

We currently need to add a “tel:” link in a mobile version of a website, but discourse keeps hijacking the URL when it is clicked, and tries to load it instead of allowing the system to open the phone app.

Thanks.


(Jay Pfaffman) #14

I understand why Discourse would hijack a URI like /blog, but not why it would hijack tel:1-555-555-12-12. What URI is getting hijacked?


(Magnetidog) #15

Hi Jay,

it considers it as a relative URL, so it rewrites the url to

http://mydomain.com/discourse/tel1-555-555-12-12

I need to go through the code and see if I can find a way to bypass this - but did not have a chance yet.


(Jeff Atwood) #16

Can you post an example link here please?


(Magnetidog) #17

Hi Jeff,

please try here:

On mobile, try clicking on the phone icon at the top (on Desktop it should just redirect you to a contact form).


(Jeff Atwood) #18

No I mean post an actual link in the form you are describing here.


(Magnetidog) #19

Jeff,

Sample TEL URL

tel:+1555555555

This seems to be the format that works on most mobile platforms.


(Kane York) #20
<a href="http://tel:+15555555555">Sample TEL URL</a>

I don’t think that’s going to work.