Forums / Setup & design / problems with links in the body of articles

problems with links in the body of articles

Author Message

Andy Sweet

Thursday 09 September 2004 6:53:04 am

Hi,

I'm new to eZpublish so don't assume I know anything! :)

I've just been through my templates to change from ezurl to ezroot, and everything seems to be working fine, except for one thing. links in the body of articles (of the type <link href=' etc) to external websites have all been changed to my eZpublish home page (http://www.stravaiging.com/a/).

you can see what I mean on this page:

http://www.stravaiging.com/a/arrivals/air

when I'm looking at the article in the editing section of the admin part, the link looks fine, but when I publish it, it automatically changes to the home page

I don't know what it is that I've changed to make this happen, can anyone help me?

Cheers
Andy

Volker Lenz

Thursday 09 September 2004 9:02:17 am

What do your URLs look like when links bounce back to your site? Note that your link-href has to be a fully qualified URL ( a thing consisting of protocol://subdomain.hostname.domain/path_to_content) in order to work as external resource request. So regardless of the url-operator you use (be it ezurl or ezroot), your links will always bounce back if they are not fully qualified, relative links. Ezurl and ezroot will both prepend the <protocol>://<subdomain>.<hostname>.<domain>/ string of your own site to relative urls. So when it comes to create links to external resources, ezurl and ezroot are not useful at all.

BTW: I recommend that you avoid using ezroot. I used it for months, according to some older docpages around. However, ezroot soon turned out to be a pain in the ass. With ezroot working only in VH-setups, you always have to provide two templates for everything, one for use with VH-setup, and another one for use with NVH-setup. That's most probably not what you want. The ez-crew has already taken appropriate steps to replace ezroot with a much smarter universal ezurl-operator in ezp 3.3. Note that ezurl works quite fine in VH-setups AND in NVH-setups. Before it decides which kind of URL to create, ezurl looks if there is sort-of an 'index.php' somewhere in your $REQUEST_URI. If not, ezurl does not put it there any more, thereby leaving all your nice VH-urls untouched. In my opinion, ezroot is clearly a deprecated operator. I guess, that the only reason why ezroot has not been withdrawn from standard-ezp so far is, that it provides a handsome method to make the template engine create some links which do not call index.php (e.g links to resources like images) in a NVH-setup, while ezurl is used for all other links in NVH.

A. Junge

Thursday 09 September 2004 11:35:40 am

I'd like to say I have the same problem.

I'm running in virtual host mode in Apache 2.0 on RedHat 9.0. I have full access to the server configuration. The redirect regex is in the VirtualHost directive in httpd.conf, and also in the .htaccess file. I have replaced ezurl with ezroot in all my templates.

Internal links work just fine. External links in the XML field (that is, they are input through the content manager, not coded in a template) get rewritten to link to my homepage. External links in templates that don't use the ezroot or ezurl operator (using straight HTML) work just fine.

So the code

<link href="http://www.otherpage.com/full/path/to/page.html">Click here!</link>

gets replaced with

<a href="/">Click here!</a>

in the generated HTML document.

Interestingly enough, if I replace ezroot with ezurl in a template, then all the internal links have the ezpublish sessionID encoded in the URL.

I originally developed the site in non-virtual host mode, and all the external links worked just fine. It's only after switching to virtual host mode that the problem showed up.

A. Junge

Andy Sweet

Saturday 11 September 2004 4:31:15 am

my links are full qualified URLs (eg. http://www.ryanair.com/) and all worked fine before I changed from ezurl to ezroot. having gone back and looked at what I changed before, I think the problem is the design/standard/templates/content/datatypes/view/ezxmltags/link.tpl template. I followed the instructions that I found on this page:

http://ez.no/ez_publish/documentation/customization/tips_tricks/creating_nice_urls

which say to change from

<a href={$href|ezurl} {section show=$target}target="{$target}"{/section}>{$content}</a>

to

<a href={$href|ezroot} {section show=$target}target="{$target}"{/section}>{$content}</a>

in link.tpl. this does remove the index.php part, which is what I wanted to do, but it then means that all my external URLs are changed to my home page (http://www.stravaiging.com/a/) while the internal links all work fine. changing the code above back again means that the external links work (but don't open in a new window even though that's what they're supposed to do) and the internal links have index.php in them again, which I don't want.

any help on how to solve this problem would be greatly appreciated, as at the moment I am quite stuck!

Cheers
Andy

A. Junge

Monday 13 September 2004 9:29:40 am

I figured out a workaround.

Instead of overriding the link.tpl template to:

<a href={$href|ezroot} {section show=$target}target="{$target}"{/section}>{$content}</a>

change it to

<a href={$href} {section show=$target}target="{$target}"{/section}>{$content}</a>

In other words, don't pipe the URL through the ezroot operator.

Unless one of the ezPublish gurus have a good reason not to do the above, that's the plan I'm sticking with.

A. Junge

Andy Sweet

Monday 13 September 2004 10:39:11 am

Hi,

This *almost* works for me, but my eZpublish files are all in a folder "a" (http://www.stravaiging.com/a/) and the solution you have suggested desn't include my "a" in them.

so instead of the links being generated as eg http://www.stravaiging.com/a/arrivals/train they are coming out as http://www.stravaiging.com/arrivals/train which is wrong. can you think of a way around this?

if not, it doesn't matter, as I found that if I change the line in ezxmltags/link.tpl back to ezurl, and keep all the others as ezroot in other templates, then all I need to do is include a full link in my articles (ie link href='http://www.stravaiging.com/arrivals/train' instead of link href='/arrivals/train') and everything works fine and index.php never appears

Cheers
Andy

Joel Hardi

Thursday 23 December 2004 3:53:58 pm

I had the same problem ... external links added in XML fields were broken and pointed to the "/" folder of my site instead of "http://www.site.com/dir/page.html" or whatever.

I fixed this by overriding the link.tpl template so that is uses ezroot for links within the site, plain $href for external links. Just one set of section tags in if/else mode, checking for the presence of a "://" in the URL. Here's the relevant bit of code:

{section show=$href|contains("://")}"{$href}"{section-else}{$href|ezroot}{/section}

And here's my complete link.tpl -- same as the stock one but with the above code in place of {$href|ezurl}:

<a href={section show=$href|contains("://")}"{$href}"{section-else}{$href|ezroot}{/section} {section show=$target}target="{$target}"{/section}>{$content}</a>

Joel Hardi

Friday 24 December 2004 12:00:00 pm

One last change ... I set it to search for ":" instead of "://" so that "mailto:" links are also fixed.

Matthew Carroll

Thursday 13 October 2005 10:27:45 am

Thanks for the great fix - just what I was looking for. For anyone else who is looking, here is the above example adapted to the current link.tpl (including the class="" and id="" elements):

<a href={section show=$href|contains(":")}"{$href}"{section-else}{$href|ezroot}{/section}{section show=$id} id="{$id}"{/section}{section show=$title} title="{$title}"{/section}{section show=$target} target="{$target}"{/section}{section show=ne($classification|trim,'')} class="{$classification|wash}"{/section}>{$content}</a>

http://carroll.org.uk