<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Balint&#039;s Blog &#187; drupal apache virtualhost url request_uri</title>
	<atom:link href="http://blog.spench.net/tag/drupal-apache-virtualhost-url-request_uri/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.spench.net</link>
	<description>balint at spench fullstop-decimalpoint-dot net</description>
	<lastBuildDate>Sun, 20 Jul 2025 18:53:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drupal request_uri returns broken absolute URLs when served from an Apache VirtualHost</title>
		<link>http://blog.spench.net/2009/07/27/drupal-request_uri-returns-broken-absolute-urls-when-served-from-an-apache-virtualhost/</link>
		<comments>http://blog.spench.net/2009/07/27/drupal-request_uri-returns-broken-absolute-urls-when-served-from-an-apache-virtualhost/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:22:49 +0000</pubDate>
		<dc:creator>balint</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[drupal apache virtualhost url request_uri]]></category>

		<guid isPermaLink="false">http://blog.spench.net/2009/07/27/drupal-request_uri-returns-broken-absolute-urls-when-served-from-an-apache-virtualhost/</guid>
		<description><![CDATA[After upgrading my Drupal site to the latest point release (5.19), before transitioning to version 6, I discovered that the action parameter of all rendered forms were being prefixed a slash &#8216;/&#8217;. This in itself is reasonable since one would expect the REQUEST_URI server variable to return a relative URL. However, as I host several [...]]]></description>
			<content:encoded><![CDATA[<p>After upgrading my Drupal site to the latest point release (5.19), before transitioning to version 6, I discovered that the action parameter of all rendered forms were being prefixed a slash &#8216;/&#8217;. This in itself is reasonable since one would expect the REQUEST_URI server variable to return a relative URL. However, as I host several websites, Drupal runs inside its own VHost with URL rewriting to enable short URLs (without the &#8216;q=&#8217; querystring). If I access Drupal directly via the web server&#8217;s address, which maps to the default VHost (this also happens to be Drupal), REQUEST_URI is relative. If I access it via the address externally visible on the web (<a href="http://spench.net/">http://spench.net/</a>) then REQUEST_URI is absolute (i.e. prefixed with the protocol and domain).</p>
<p>The Druapl &#8216;request_uri&#8217; function in includes/bootstrap.inc always adds a slash to the beginning of the server variable REQUEST_URI, which will break any absolute URLs.</p>
<p>The following modification (the <strong>strpos</strong> check) resolves this issue:</p>
<p><code>/**<br />
* Since $_SERVER['REQUEST_URI'] is only available on Apache, we<br />
* generate an equivalent using other environment variables.<br />
*/<br />
function request_uri() {<br />
&nbsp;&nbsp;if (isset($_SERVER['REQUEST_URI'])) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER['REQUEST_URI'];<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (isset($_SERVER['argv'])) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['argv'][0];<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;if (strpos($uri, '/') == 0)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Prevent multiple slashes to avoid cross site requests via the FAPI.<br />
&nbsp;&nbsp;&nbsp;&nbsp;$uri = '/'. ltrim($uri, '/');<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return $uri;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spench.net/2009/07/27/drupal-request_uri-returns-broken-absolute-urls-when-served-from-an-apache-virtualhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
