You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Neil Freeman <ne...@asa.co.uk> on 2004/03/22 11:25:57 UTC

[users@httpd] Newbie rewrite question regarding absolute URLs

I hope someone here can help me. I have the following image:

     http://www.oursite/images/title.gif

Within a page I can refer to this image using an absolute URL as such:

     <img src="/images/title.gif" />

This works fine as long as pages stay where they are. We are in the 
process of changing hosting company at the moment and before our site 
goes live and DNS records are changed, we can only access our site using 
a URL as such:

     http://www.newhost.com/ourcompany/

This subsequently breaks all of our absolute URLs due to the 
'/ourcompany/' section of the URL. Is there any way I can set up Apache 
(using a .htaccess files and mod_rewrite?) so that *all* absolute 
requests are rewritten to include the '/ourcompany' section of the URL? 
So that:

     <img src="/images/title.gif" />

works as if I had actually used the following reference:

     <img src="/ourcompany/images/title.gif" />

Any help or thoughts greatly appreciated.

Neil


This communication is confidential to the intended recipient(s). If you are not that person you are not permitted to make use of the information and you are requested to notify the sender immediately of its receipt then destroy the copy in your possession. Any views or opinions expressed are those of the originator and may not represent those of Advanced System Architectures Ltd.

*** This Email Has Been Virus Checked ***


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Newbie rewrite question regarding absolute URLs

Posted by Brian Dessent <br...@dessent.net>.
Neil Freeman wrote:

> This subsequently breaks all of our absolute URLs due to the
> '/ourcompany/' section of the URL. Is there any way I can set up Apache
> (using a .htaccess files and mod_rewrite?) so that *all* absolute
> requests are rewritten to include the '/ourcompany' section of the URL?

Apache does not know a relative URL from an absolute URL.  The browser
always requests the entire/full pathname of the object.  The browser
uses the contents of the html as well as its knowledge of the current
URL to create the request.

However you could try something like:

RewriteEngine On
RewriteCond !^/ourcompany
RewriteRule ^(.*)$ /ourcompany$1

If this is in a htaccess file you'll probably need a "RewriteBase /"
assuming you put this in the docroot.

Brian

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org