Mailing List Archive

Porting mod_rewrite rules
I'm having some troubles figuring out how to get a rewrite rule I have
in a .htaccess file ported over.
The basic ones are working fine it's just the rule we have for dealing
with requests for our CSS and image files from a relative path.
Those files are kept in the folder "http://domain.com/includes/images/"
and "http://domain.com/includes/css" and we use relative links to point
to them.

When they hit a link for the contact page (http://domain.com/contact or
just /contact ) there is an internal redirect that points to
http://domain.com/index.php?id=contact
This is simple and working fine.

Where the trouble pops up is our includes as the browser is now looking
for http://domain.com/contact/includes/images/logo.jpg instead of where
it really is: http://domain.com/includes/images/logo.jpg
In Apache we had this handles by the following rule which worked fine as
it was only run once:
RewriteRule ^([a-z0-9-_./]+)/includes/([a-z0-9-_./]+)$ includes/$2

This does not work in Cherokee as it seems to keep running the rule over
and over again till it spits out (external was selected to see output):
http://domain.com/contact/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/logo.jpg

My question is whether this can be done without resorting to a rule per
subpage or without having to to change our links to absolute links.
The reason we don't want a rule per subpage is the web designers don't
have access to cherokee-admin to add rules so it's best to have one or
two rules that can handle having new pages thrown at it as well as pages
getting removed. The reason absolute links aren't used is it's more
efficient (or lazy, however you want to look at it) for doing testing
and development before going live as well as allowing previews for clients.
_______________________________________________
Cherokee mailing list
Cherokee@lists.octality.com
http://lists.octality.com/listinfo/cherokee
Re: Porting mod_rewrite rules [ In reply to ]
On Thu, Nov 17, 2011 at 9:01 AM, Mini IT <miniit@rileys.com> wrote:

> Where the trouble pops up is our includes as the browser is now looking
> for http://domain.com/contact/**includes/images/logo.jpg<http://domain.com/contact/includes/images/logo.jpg>instead of where it really is:
> http://domain.com/includes/**images/logo.jpg<http://domain.com/includes/images/logo.jpg>
> In Apache we had this handles by the following rule which worked fine as
> it was only run once:
> RewriteRule ^([a-z0-9-_./]+)/includes/([a-**z0-9-_./]+)$ includes/$2
>
>
While this approach may work, it is very inefficient as all your images
would have multiple URLs (and hence won't cache effectively). Two
solutions to this issue are:
1. Use absolute links for in your HTML and CSS files (/images/... instead
of just images/...)
2. Put a <base> tag in your HTML (although this will affect *all* relative
links on the page, and hence might break things)

I'd suggest looking in to option #1.
Re: Porting mod_rewrite rules [ In reply to ]
Sorry, I skimmed your message and didn't notice the last bit about why you
don't want to use absolute links. On my personal site (http://dan.cx/) I
use a <base> tag which has href="http://dan.cx/" in the live environment
and href="http://localhost/dan.cx/" in the development environment, which
lets me use relative image links that work correctly. You could always use
hostnames (like dev.domain.com or domain.com.dev) in the hosts file for the
dev environment, which would let you use absolute links.

On Thu, Nov 17, 2011 at 9:01 AM, Mini IT <miniit@rileys.com> wrote:

> I'm having some troubles figuring out how to get a rewrite rule I have in
> a .htaccess file ported over.
> The basic ones are working fine it's just the rule we have for dealing
> with requests for our CSS and image files from a relative path.
> Those files are kept in the folder "http://domain.com/includes/**images/<http://domain.com/includes/images/>"
> and "http://domain.com/includes/**css <http://domain.com/includes/css>"
> and we use relative links to point to them.
>
> When they hit a link for the contact page (http://domain.com/contact or
> just /contact ) there is an internal redirect that points to
> http://domain.com/index.php?**id=contact<http://domain.com/index.php?id=contact>
> This is simple and working fine.
>
> Where the trouble pops up is our includes as the browser is now looking
> for http://domain.com/contact/**includes/images/logo.jpg<http://domain.com/contact/includes/images/logo.jpg>instead of where it really is:
> http://domain.com/includes/**images/logo.jpg<http://domain.com/includes/images/logo.jpg>
> In Apache we had this handles by the following rule which worked fine as
> it was only run once:
> RewriteRule ^([a-z0-9-_./]+)/includes/([a-**z0-9-_./]+)$ includes/$2
>
> This does not work in Cherokee as it seems to keep running the rule over
> and over again till it spits out (external was selected to see output):
> http://domain.com/contact/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/**includes/images/includes/**
> images/includes/images/logo.**jpg<http://domain.com/contact/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/logo.jpg>
>
> My question is whether this can be done without resorting to a rule per
> subpage or without having to to change our links to absolute links.
> The reason we don't want a rule per subpage is the web designers don't
> have access to cherokee-admin to add rules so it's best to have one or two
> rules that can handle having new pages thrown at it as well as pages
> getting removed. The reason absolute links aren't used is it's more
> efficient (or lazy, however you want to look at it) for doing testing and
> development before going live as well as allowing previews for clients.
> ______________________________**_________________
> Cherokee mailing list
> Cherokee@lists.octality.com
> http://lists.octality.com/**listinfo/cherokee<http://lists.octality.com/listinfo/cherokee>
>
Re: Porting mod_rewrite rules [ In reply to ]
Thanks for the help!
What I ended up doing was creating a directory rule for each (like a
directory rule for /contact) and used the redirect handler there.
I used the html base tag as well and kept the default rule as list and send.
Now things seem to be working fine though I am disappointed I couldn't
keep this more dynamic so the web developers don't have to worry about
asking for rules to be created when needed..

On 11/16/2011 7:04 PM, Daniel Lo Nigro wrote:
> Sorry, I skimmed your message and didn't notice the last bit about why
> you don't want to use absolute links. On my personal site
> (http://dan.cx/) I use a <base> tag which has href="http://dan.cx/" in
> the live environment and href="http://localhost/dan.cx/" in the
> development environment, which lets me use relative image links that
> work correctly. You could always use hostnames (like dev.domain.com
> <http://dev.domain.com> or domain.com.dev) in the hosts file for the
> dev environment, which would let you use absolute links.
>
> On Thu, Nov 17, 2011 at 9:01 AM, Mini IT <miniit@rileys.com
> <mailto:miniit@rileys.com>> wrote:
>
> I'm having some troubles figuring out how to get a rewrite rule I
> have in a .htaccess file ported over.
> The basic ones are working fine it's just the rule we have for
> dealing with requests for our CSS and image files from a relative
> path.
> Those files are kept in the folder
> "http://domain.com/includes/images/" and
> "http://domain.com/includes/css" and we use relative links to
> point to them.
>
> When they hit a link for the contact page
> (http://domain.com/contact or just /contact ) there is an internal
> redirect that points to http://domain.com/index.php?id=contact
> This is simple and working fine.
>
> Where the trouble pops up is our includes as the browser is now
> looking for http://domain.com/contact/includes/images/logo.jpg
> instead of where it really is:
> http://domain.com/includes/images/logo.jpg
> In Apache we had this handles by the following rule which worked
> fine as it was only run once:
> RewriteRule ^([a-z0-9-_./]+)/includes/([a-z0-9-_./]+)$ includes/$2
>
> This does not work in Cherokee as it seems to keep running the
> rule over and over again till it spits out (external was selected
> to see output):
> http://domain.com/contact/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/includes/images/logo.jpg
>
> My question is whether this can be done without resorting to a
> rule per subpage or without having to to change our links to
> absolute links.
> The reason we don't want a rule per subpage is the web designers
> don't have access to cherokee-admin to add rules so it's best to
> have one or two rules that can handle having new pages thrown at
> it as well as pages getting removed. The reason absolute links
> aren't used is it's more efficient (or lazy, however you want to
> look at it) for doing testing and development before going live as
> well as allowing previews for clients.
> _______________________________________________
> Cherokee mailing list
> Cherokee@lists.octality.com <mailto:Cherokee@lists.octality.com>
> http://lists.octality.com/listinfo/cherokee
>
>