diff --git a/middleman-core/features/helpers_link_to.feature b/middleman-core/features/helpers_link_to.feature
index 162c1e8a0..d6caf6cf5 100644
--- a/middleman-core/features/helpers_link_to.feature
+++ b/middleman-core/features/helpers_link_to.feature
@@ -5,6 +5,24 @@ Feature: link_to helper
When I go to "/link_to_erb.html"
Then I should see "erb with html tags"
+ Scenario: link_to works with absolute URLs (where the relative part matches a local path)
+ Given a fixture app "link-to-app"
+ And a file named "config.rb" with:
+ """
+ set :relative_links, true
+ """
+ And a file named "source/test.html.erb" with:
+ """
+ Hello
+ """
+ And a file named "source/link_to_absolute.html.erb" with:
+ """
+ <%= link_to "test", "http://google.com/test.html" %>
+ """
+ And the Server is running at "link-to-app"
+ When I go to "/link_to_absolute.html"
+ Then I should see 'test'
+
Scenario: link_to works with blocks (slim)
Given the Server is running at "link-to-app"
When I go to "/link_to_slim.html"
diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb
index 7a4e2d351..1c4b74edb 100644
--- a/middleman-core/lib/middleman-core/util.rb
+++ b/middleman-core/lib/middleman-core/util.rb
@@ -169,14 +169,14 @@ def url_for(app, path_or_resource, options={})
if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
resource = path_or_resource
resource_url = url
- elsif this_resource && uri.path
+ elsif this_resource && uri.path && !uri.host
# Handle relative urls
url_path = Pathname(uri.path)
current_source_dir = Pathname('/' + this_resource.path).dirname
url_path = current_source_dir.join(url_path) if url_path.relative?
resource = app.sitemap.find_resource_by_path(url_path.to_s)
resource_url = resource.url if resource
- elsif options[:find_resource] && uri.path
+ elsif options[:find_resource] && uri.path && !uri.host
resource = app.sitemap.find_resource_by_path(uri.path)
resource_url = resource.url if resource
end