You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jay Levitt <ja...@jay.fm> on 2005/04/25 18:58:33 UTC

[users@httpd] mod_rewrite and relative URLs

I have the following requirements for a site I'm building:

- For bureaucratic reasons, I have only one UNIX account, only one 
subdomain, and no access to httpd.conf itself.  (That may change, so if 
you can think of a solution that would otherwise work, please post it!)

- I wish to have "system root" (my term) subdirectories /prod, /staging, 
and /dev to hold the production site, ready-for-production, and 
development versions of the site.

- The main content for each site is currently being generated by 
MovableType, and will be stored in $SYSTEM_ROOT/mt-pages.  (I don't like 
having subsystem-specific files in the root directory.)

- Each site also uses other subsystems like vBulletin, a survey script, 
etc., which are stored in $SYSTEM_ROOT/forum, $SYSTEM_ROOT/survey, etc.

- Requests for www.example.com/file.ext should be rewritten to 
www.mysite.com/prod/file.ext.

- Requests for any www.example.com/$SYSTEM_ROOT/file.ext should be 
rewritten to $SYSTEM_ROOT/mt-pages/file.ext.

- BUT requests for www.example.com/$SYSTEM_ROOT/subdir/file.ext should 
remain unchanged.

So far, so good.  I have RewriteRules in an .htaccess in ServerRoot to 
point it to prod, and similar rules in each $SYSTEM_ROOT dir to point 
into mt-pages for any filename with a dot in it.  (I'm OK limiting 
myself to directories without dots.)

The problem, of course, is that if I request 
http://www.example.com/index.html, which gets rewritten to 
http://www.example.com/prod/mt-pages/index.html, any relative links to, 
say, "images/logo.gif" will look for /images/logo.gif, not /prod/mt-
pages/images/logo.gif.

I can solve this by adding a BASE tag to each page, or by using absolute 
URLs, but that kills the point of having these mirror-image test 
systems.

I could also solve it by explicitly checking for each known subsystem in 
the .htaccess file, rather than assuming any directory to be a top-level 
subsystem, but I'd prefer to avoid that.

Is there some solution with mod_rewrite, mod_alias, or something else 
that will let me rewrite both URLs and the content base?  This seems 
like it ought to be a common problem.


-- 
Jay Levitt                | 
Wellesley, MA             | I feel calm.  I feel ready.  I can only
Faster: jay at jay dot fm | conclude that's because I don't have a
http://www.jay.fm         | full grasp of the situation. - Mark Adler


---------------------------------------------------------------------
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] mod_rewrite and relative URLs

Posted by Joshua Slive <js...@gmail.com>.
On 4/25/05, Jay Levitt <ja...@jay.fm> wrote:
> Is there some solution with mod_rewrite, mod_alias, or something else
> that will let me rewrite both URLs and the content base?  This seems
> like it ought to be a common problem.

>From a quick read, I don't see any way to solve this problem without
rewriting all the URL references inside the pages you are sending. 
That, in turn, is not an easy thing to do.  But you can look at some
of Nick's modules:
http://apache.webthing.com/

Joshua.

---------------------------------------------------------------------
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