drupal prepending 'node' to the link url

188 views Asked by At

I am working on a drupal site. The current issue is that when a link is created either by using the url() or the base_path variable, it works ok on local development environment but when the very same code is put on the server, the url prepends node string in the path.

e.g. the path is <drupal site>/latestnews . The generated path is <drupal site>/node/latestnode and when clicked, it shows the page not found error. However would like to mention that the links work fine (i.e generate correct path) when clicked from the home page.

any help would be appreciated. If it helps, I am using Pantheon hosting for testing.

3

There are 3 answers

1
Andrew Schulman On

Does the server by chance have the pathologic module enabled? That module's job is to rewrite links for different locations. It may be misconfigured. If it is enabled, try disabling it, or adjusting its configuration in each of your text formats (admin/config/content/formats).

1
geoandri On

Have you checked if the $base_url variable in the 'sites/default/settings.php' file has the correct value? According to documentation "if Drupal is generating incorrect URLs on your site, which could * be in HTML headers (links to CSS and JS files) or visible links on pages * (such as in menus), uncomment the Base URL statement (remove the * leading hash sign) and fill in the absolute URL to your Drupal installation."

0
Dave F On

I had the exact same problem and fixed it.

Initially, my site was NOT using clean urls. When I ENABLED clean urls and rewrote my links so that they weren't preceded by the string "?q=", this broke my hard coded links. This is because when clean urls are NOT used, pages appear to be in the root directory, but when clean urls ARE used, they appear to be inside of folders.

The following example shows how updating a page to use clean urls can affect it.

Clean_urls_DISABLED
Page: SITE?q=node/7
Hard_coded_link_in_page: ?q=node/9
Link_displayed_in_browser: SITE?q=node/9

Clean_urls_ENABLED
Page: SITE/node/7
Hard_coded_link_in_page: node/9
Link_displayed_in_browser: SITE/node/node/9

Notice that the page that was updated to use clean urls, has "node/node" in its link when it is displayed in the browser.

The solution is to prepend "../" to all hard coded urls (for pages other than your front page). That way hard coded links for other contents, such as images, will work as well.

Clean_urls_ENABLED
Page: SITE/node/7
Hard_coded_link_in_page: ../node/9
Link_displayed_in_browser: SITE/node/../node/9
Hard_coded_image_source_in_page: ../sites/default/files/img.jpg
Image_source_in_browser: SITE/node/../sites/default/files/img.jpg

This will work for hard coded paths for links, images, and any other elements that contain paths referencing files/documents.