1

Is there a way to "alias" a Drupal site node to an external URL?

I'd like that a click on a link in my Drupal site like 'http://mysite/node/64' redirects to an address like 'http://anothersite/whateverurl'.

I use Fullcalendar View module.
I added a Date range field to a custom content of mine (my modified Basic page).
If I set a date in a node of that type, I can see an item linked to it in the Calendar: enter image description here If I click on the item, I am redirected to the corresponding node and I see its content.
For some nodes, I'd like the link to point to an external url instead...

[Edit]
I tried something else: I created a new View with no fields at all except the Daterange.
When I use Format: Unformatted list, I get this result: enter image description here which is OK as I have only one node of the type filtered.
When I use Format: Full Calendar Display, I get this result:
enter image description here which is strange as I have no fields in the View description pointing to the node itself...
Does it mean that Fullcalendar View] module generates its magic elsewhere?
I'm a bit confused :-(
Any help?

7
  • If you're redirecting why would you also have a node? Can't you just redirect the URL at vhost/.htaccess level?
    – Clive
    Commented Sep 6, 2018 at 11:09
  • Or with the same result in a request event subscriber, example before routing How do I redirect users visiting a path matching a regular expression? , which you can also do with a lower priority after routing to catch aliases of the node.
    – 4uk4
    Commented Sep 6, 2018 at 11:16
  • Updated my question to clarify why...
    – gbmapo
    Commented Sep 6, 2018 at 11:35
  • You'd be better off keeping that external URL in a field attached to the node, then overwriting the Views row template to link it based on that value if available
    – Clive
    Commented Sep 6, 2018 at 11:36
  • Any clue how to do that?
    – gbmapo
    Commented Sep 7, 2018 at 19:43

3 Answers 3

1

Since you want this done in a view here is a possible solution

  1. Add a link field to your content type external url which would need to be followed when available otherwise (if empty) it would take to node view (normal behaviour).

Modify the Fullcalendar View and add follow 2 fields

  1. Link to content hidden enter image description here

  2. external url and adjust the No results behaviour to include {{ view_node }} enter image description here

  3. Use external url as the link

NOTE: it appears that Fullcallendar view module takes the link to node in a way that it cannot be modified within the view as described above. There is a feature request that asks for such an option. In the meantime perhaps the above can be achieved with another calendar module () or modify the URL from within a custom module.

6
  • Sorry. I couldn't make your proposal work. I don't understand your 4th point: Use external url as the link. How do I do that?
    – gbmapo
    Commented Sep 7, 2018 at 12:32
  • @gbmapo your calendar view outputs a field that is the actual link. Change that field to use the external URL output instead, you can post a screenshot of your calendar View configuration
    – GiorgosK
    Commented Sep 7, 2018 at 12:53
  • I updated my question...
    – gbmapo
    Commented Sep 7, 2018 at 19:42
  • I just read your NOTE. Any clue where I can put the code in my custom module? what should be the proper hook_views to be used?
    – gbmapo
    Commented Sep 18, 2018 at 8:39
  • @gbmapo I believe this functionality is hardcoded in template_preprocess_views_view_fullcalendar function in fullcalendar_view.theme.inc file. Its a template function so you can probably copy paste it in your THEMENAME.module and rename it to THEMENAME_preprocess_views_view_fullcalendar. I think what needs changing is on line 154 'url' => $current_entity->toUrl()->toString(),
    – GiorgosK
    Commented Sep 18, 2018 at 9:18
0

Lets say you have a node on your website example.com/node/123 with an alias to it example.com/my-node

If what you need is:

  • when a user try to access the node by going to example.com/node/123, so he will be redirected to an external url.

  • but when the user access the node by going to example.com/my-node, no redirection and he will normally have access to the node page.

If this what you are asking about, reply to my answer here and i will gibe you a full tutorial on how to do it !

Otherwise, as @clive mentioned, your question does not make sense ! And for what you need the node if you are not going to use it.

4
  • Updated my question to clarify why...
    – gbmapo
    Commented Sep 6, 2018 at 11:35
  • For some nodes, I'd like the link to point to an external url instead... does those nodes have in the url anything to distinguish them from the other nodes ? What is the difference between those nodes you want to redirect and the others with no redirection ? (Field, url, title..!?!) Commented Sep 6, 2018 at 11:45
  • I thought to create a specific content type for that...
    – gbmapo
    Commented Sep 6, 2018 at 12:14
  • 1
    As very straight solution, you can use rules module or business rules module and create a condition to fire a page redirect action when for example certain arguments are available in the url or when a specific node field = to a specific value. Meaning: if the node you want to be redirected to an external url has the title field contains for example the world external so you can add a condition to check the title of every loaded node, if the title contains tbe word external* so fire a **page redirect action to whatever url you want. Hope it helps !!! Commented Sep 6, 2018 at 14:12
0

It's not easy to do this, as the other answers show.

I wrote a module called "Alien Alias" which does this, it can link to internal or external locations. It also lets you keep stats of the clicks (if you want it to).

(Optionally) it intercepts very early in the page build process to redirect away, although you can let it build a whole page and then redirect.

Here: https://drupal.org/project/alien_alias

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.