Questions tagged [uri]

A "Uniform Resource Idendifier" identifies a resource on a network.

Filter by
Sorted by
Tagged with
47
votes
5answers
65k views

How do I get the node ID from the URL?

So far, I came across these 3 functions in Drupal 7, but I am not really sure what the difference between them is, and which is more appropriated to get the node ID in a block preprocess function. ...
41
votes
4answers
53k views

How to get the base URL of a site

My site is on http://drupal8.local/. How do I get the drupal8.local part of that URL? Url::fromRoute('<'current'>') or base_path() returns the path parth of the URL; For example, for http://...
38
votes
9answers
63k views

How to get the valid URL of a Link field from within a Twig template?

I have a Link field named field_my_link (machine name). Within a Twig template I can get the link's URL value with this: {{ node.field_my_link.uri }} If inside the Link's URL there is an external ...
38
votes
9answers
44k views

How do I change a theme based on the URL?

I have a Drupal instance running on example.org. Which has a theme X installed and activated. Now for a limited period an event is supposed to be held on the site for which a special section has been "...
32
votes
5answers
52k views

How do I get the full URL of the current page?

I need to get the full URL of the currently opened page. I use the following code, but it returns http://localhost/mysite/page_name. $path = isset($_GET['q']) ? $_GET['q'] : '<front>'; $link =...
22
votes
3answers
34k views

How do I get the node URL in a Twig template?

I am trying to get the node URL in a Twig template. {{ content.node_link }} returns the full link, but I only need the URL. How do I retrieve the node URL?
19
votes
4answers
11k views

Clean urls - auto path alias - how to remove accents (Á É Ó Í Ñ ) from the urls?

I´m using Drupal 7.9 and pathauto 7.x-1.0-rc2 I want to remove the accents from the paths and replace them with normal letters Á=A É=E Ó=O Í=I Ñ=N etc. I'm using a taxonomy field type and node ...
15
votes
2answers
31k views

How do I change the base URL?

In Drupal 7, we can quickly change the base URL of the website. How can I do this, in Drupal 8?
13
votes
4answers
28k views

how to get the absolute path for files based on fid

How can i get the absolute path for a file based on the fid? Sorry if this is a repeat, I did a search but was unable to find the answer.
12
votes
1answer
5k views

Load a file entity by URI

Is there a way to load a file by URI in Drupal 8 or Drupal 9? In Drupal 7 it is possible by the next example: $uri = 'public://file.xyz'; // Take a look at: file.inc::file_load_multiple $files = ...
11
votes
4answers
17k views

drupal_goto(request_uri()) replaces my '?', '=' and '&' in url

I need to redirect user from a page with example.com/node/add/dispo?arg1=1&arg2=2 to the same type of URL. But when I simply do a drupal_goto(request_uri());, it redirects my user to example.com/...
11
votes
5answers
753 views

How to start views at %nid position (from path)?

I have a portfolio showing somes nodes (views3 + views slideshow using cycle). Everything works fine, I've a default path /portfolio to access to it. However, I'm trying to set a path for each slide. ...
10
votes
8answers
26k views

How to detect the current URL?

I would like to add a body class in D6 if you are on a specific page(s) currently in my template.php I have: if url('the/path') { add the body class... } but that function doesn't seem to be ...
10
votes
4answers
3k views

How to force the canonical URL to use http?

On our page we use the Metatag module to show a canonical meta tag. In the configuration we use the [current-page:url:absolute] token. This works fine, but the problem is, that whether the page gets ...
9
votes
1answer
18k views

How do I enable clean URLs with Nginx?

I'm using Drupal 7.x. I have achieved to make it work without clean URLs. Investigating, I have understood that I should create a vhost for each drupal site and enable clean URLs with the following ...
8
votes
2answers
27k views

How to change my base URL

I have built a website using drupal. Now, the base URL is http://xxx.xxx.xxx.xxx/drupal. But I want to change base URL as http://xxx.xxx.xxx.xxx How do I do? Thanks.
8
votes
5answers
7k views

How to get a user's profile picture URL?

I need to get the user's profile picture using the following code: \Drupal::service('renderer')->renderPlain(\Drupal\user\Entity\User::load(\Drupal::currentUser()->id())->user_picture->...
8
votes
2answers
8k views

How to find the list of 'paths' on my site?

I recently became the administrator of a Drupal site. I am attempting to configure various blocks on the page, and have so far only succeeded in removing them altogether. The configuration menu tells ...
8
votes
1answer
8k views

What is the URL to set the admin theme?

The URL to change the admin theme isn't the same in Drupal 7 compared to 6. What is the new URL?
8
votes
3answers
8k views

Clean URL's Test Failed in D 7

I am tired of finding solution for this issue.. I have tried allmost allthings. But It doesn't work for me. What I have tried is given below: uncommenting RewriteBase / Changing the syntax of ...
8
votes
3answers
11k views

How to convert URL aliases back to node ID

I wonder how to convert a URL path back to it's own node (node/nid). I wish to get the original node ID from a given path. e.g. path = "news/my-news" ..and trace it back to get it's own original URL,...
8
votes
2answers
6k views

Get an image with style url from an URI in twig

So thanks to 4k4 I finally managed to get my original image URI in a field template via item.content['#item'].entity.uri.value and with {{ file_url(item.content['#item'].entity.uri.value) }} I ...
7
votes
3answers
32k views

How do I get the public url of a file from the uri or filename

I'm using php from with a view (Views PHP) I'm trying to extract the real url of a file from a file reference. I am able to get the the uri of the file and or the filename. What drupal function can I ...
7
votes
2answers
11k views

How do I redirect to an external URL?

Drupal 7 has drupal_goto() that would allow redirecting to an external url. The change record indicated that ControllerBase::redirect is the method to be called in D8. https://www.drupal.org/node/...
7
votes
5answers
26k views

Get the site base url in template.php

How do i get the base url in template.php? None of the below works. global $base_url; global $base_path; global $base_root;
7
votes
3answers
5k views

How to make URL arguments available as tokens in Rewrite Results of a Field in a View?

Is it possible to make URL arguments, e.g. http://mysite.com/arg1/arg2/arg3 available as tokens in the rewrite results settings for a field in views e.g. for the above these would be available for ...
7
votes
5answers
3k views

Proper way to get the base path when including an image from a module?

When using just drupal_get_path() to include an image from a module directory, this produces non-existent urls when using language prefixes. I've seen a couple of modules prepend base_path() to deal ...
7
votes
3answers
13k views

Get image's URL as a token for use in Views' replacement pattern

I need to get an image's full URL path as a token that I can use as a replacement pattern in Views. I'm trying to have one thumbnail image link to a larger image. I have the larger image excluded ...
7
votes
1answer
8k views

Programmatically set URL Alias when creating node in form plugin

I'm currently importing data from a database to create nodes based on them. My node save code looks like this $node = \Drupal\node\Entity\Node::create([ 'type' => 'issue', ...
7
votes
1answer
4k views

How to get the Route object from an URI?

If I have a Url object, or even a simple string representation of path such as /node/2, how can I get the full Route object?
7
votes
1answer
6k views

Clean URLs disabled even though module-rewrite is on

I have a manually installed LAMP environment on Ubuntu 15.10 Desktop and when I came to install Drupal 8 on it i've seen that clean URLs are disabled, so I turned on the Apache2 (2.4.12) rewrite ...
6
votes
3answers
13k views

How to get the URL of a file located in the theme folder?

Is there a way to get the URL of an image located in the theme folder? Or just get the URL of the theme folder?
6
votes
2answers
10k views

Why are tokens added to image URLs?

When I'm use the image_style_url(), function I got this token at the end of the URL: ?itok=yjoxJwQh. Drupal uses a different token for styles and script, eg ?mk4o7m. How does this affect caching and ...
6
votes
3answers
16k views

How can I get an absolute path to a theme?

Is there a Drupal function that returns the absolute theme path? Or is there a canonical / base practice way of doing this correctly returning the theme path? What I've found so far is this: <?...
6
votes
4answers
3k views

User URLs based on the usernames

Is there a module that changes the user URL from "user/1" to "user/username"?
6
votes
6answers
4k views

How to display a block on only the listed pages using wildcard and excluding subpages?

I have a block I'm displaying using block setting's "Only the listed pages". I'm using a wild card asterisk to show the block on any pages following about-us/. For example: about-us/* The problem is ...
6
votes
1answer
1k views

Can I access public:// from inside a module?

I need to load an image that's uploaded to the public folder from within a module In the module itself: function mymodule_dashboard() { GLOBAL $user; $profile = profile2_load_by_user($user->...
6
votes
4answers
13k views

How to add canonical links on ALL URL's?

What is the best way to get canonical links on ALL URL's in D7? I see nodes already have relative canonicals but I have a site with a lot of non node URL's that also need canonicals. I added code to ...
6
votes
2answers
110 views

Get more drupal.org project usage information

Choosing a Drupal module has become an art-form. Deciding if the module is active, used frequently, growing in usage, etc. is important. I'm a site builder. https://drupal.org/project/usage has lot'...
6
votes
1answer
8k views

Drupal behind a SSL offloading reverse proxy — is this config correct?

We are transitioning an existing drupal installation to run as a SSL-only site behind a SSL offloading proxy. Drupal itself has no SSL and is running on port 80 on apache. We've got what we think is ...
6
votes
1answer
3k views

Add url alias with parameter (?foo=bar)

I need to create urls aliases like this: /mypath?foo=bar&foo2=bar2 (source) -> /foo/bar (alias) via standard drupal alias url add (admin/config/search/path), but when I insert that link in ...
5
votes
7answers
19k views

How can I enable clean URLs?

I installed Drupal 7 on Wamp Server. I can't find any checkbox or link to enable clean URLs; I see only the Run the Clean URL Test button. How can I enable clean URLs?
5
votes
3answers
1k views

How to restrict access to a node via node/12 and allow access via a path like content/sometitle?

Problem: I want to restrict direct node access using node number www.example.com/node/12 and allow access using pathauto alias www.example.com/content/sometitle to anonymous user. This user should be ...
5
votes
4answers
12k views

Getting arguments from URL

How do I get arguments from the URL? in other words, what is the equivalent of the arg() function of Drupal 7 and previous versions?
5
votes
3answers
8k views

How do I reset the clean URLs?

Another developer has sent me a completed Drupal 7 website. When I installed it, the home page uses clean URLs, which don't work; example.com/index.php?q=/node/123 does work. When I go to example....
5
votes
1answer
20k views

How to add additional url parameters?

I would like to know how I can include additional URL parameters to a given link? ie: 'news?pid=3' <?php print $path='news?pid=3'; ?> This returns page not found error as the '?' is getting ...
5
votes
2answers
2k views

how do display 404 while the url didn't exits

I add a view contains three display page,and the page urls are: questions questions/my questions/unanswered but when I visit the url questions/s12dsdd ,It display the questions page list all ...
5
votes
1answer
113 views

l() is printing “http://node/16” when gets “/node/16” as argument

This site was copied to a new domain when it started breaking. Is there some setting somewhere I need to update, so it knows how to build working URLs again?
5
votes
2answers
4k views

How to check if page exists using page alias in D7?

In D7, how do I check whether a page exists by page alias? I've found some guy asking the same very question but I have problems with using menu_valid_path() (or drupal_valid_path() in D7) function. ...
5
votes
3answers
2k views

How to access all images uri in node's field in custom module?

I already know I can get an url for field of node this way: $src = file_create_url($node->get('name_of_image_field')->entity->uri->value); The problem is, my field name_of_image_field ...

1
2 3 4 5
23