ericmckean / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

RewriteRule not working on 1&1 hosting #142

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Minify version: 2.1.3
PHP version: 5.2.11

What steps will reproduce the problem?
1. Minify CSS
2. Try URI without '?'

Expected output: Should load correct CSS

Actual output: Endless Redirect

Did any unit tests FAIL? (Please do not post the full list) No.

I have a problem with mod_rewrite on a 1&1 shared server. I am pretty sure
this is should be solvable but I am no expert in mod_rewrite, so I am
having a hard time solving this.

When I use the builder it warns me about my server supposedly not
supporting mod_rewrite. I had actually removed the "<IfModule
mod_rewrite.c>" directive from the .htaccess file since 1and1 supports
mod_rewrite.

I have my Minify installed on my server on a subdomain like:

assets.myserver.com/min

When I access my minified CSS file by the URL path
"/min/?f=css/styles.css", everything is fine.

When trying to use the URL path "/min/f=css/styles.css" (notice the missing
"?") I get a 404. That might be expected.

When trying the URL path "/min/index.php/f=css/styles.css" though (notice
the added "/index.php"), after a while I get a server error about an
endless redirect. The URL I see in Firefox now reads:

http://assets.myserver.com/min/index.php/f=css/builder/builder/builder/builder/b
uilder
[...]

Does anyone know what exactly is happening here?

Original issue reported on code.google.com by shuffle...@gmail.com on 29 Sep 2009 at 11:53

GoogleCodeExporter commented 9 years ago
Two issues here:

1. /min/index.php/f=css/styles.css will never work because the app doesn't read 
PATH_INFO, just querystring vars, f or g.

With no f or g set, it falls through to the Builder redirect, which is done via 
"Location: builder/" (a relative URI, invalid but works in all browsers). 
Hence, it 
keeps trying to redirect to the builder, never getting there.

2. Rewriting isn't working on your host. Particularly:

/min/?f=css/styles.css  and  /min/f=css/styles.css
...should produce the same output.

Try adding a RewriteBase:

RewriteEngine on
RewriteBase /min/
RewriteRule ^([a-z]=.*)  index.php?$1  [L,NE]

Original comment by mrclay....@gmail.com on 29 Sep 2009 at 7:06

GoogleCodeExporter commented 9 years ago
You were right, RewriteBase was the key. I also used a RegEx tester to redo the
pattern matching. This works fine now for me:

RewriteBase /min
RewriteRule ([gf]=.*) index.php?$1 [L,NE]

Original comment by shuffle...@gmail.com on 29 Sep 2009 at 9:03

GoogleCodeExporter commented 9 years ago
I'd prefer to put this in the next version:

RewriteEngine On

# You may need to uncomment this on some servers
#RewriteBase /min

# rewrite URLs like "/min/f=..." to "/min/?f=..."
RewriteRule ^([bfg]=.*)  index.php?$1 [L,NE]

1. [bfg] allows you to use a base path: /min/b=css&f=a.css,b.css

2. ^ makes sure that the pattern begins directly after "/min/". If you don't, 
you 
risk breaking URLs like "/min/foo/bar.php?a=someValue". Minify doesn't have any 
such 
scripts (yet), but I like very targeted rewriting.

Does the above work on 1&1 if you uncomment the RewriteBase?

Original comment by mrclay....@gmail.com on 29 Sep 2009 at 9:59

GoogleCodeExporter commented 9 years ago
Yeah, that works!

Original comment by shuffle...@gmail.com on 30 Sep 2009 at 11:41

GoogleCodeExporter commented 9 years ago
Hi,
I did CSS and JS min without ?g=...., all works OK.
PageSpeed show me 98 and YSlow 92 Point. 
But Google Webmaster Tools "Site Performance" show me, very bad resoults:

On average, pages in your site take 3.4 seconds to load (updated on Jan 18, 
2010).
This is slower than 56% of sites.
--------------------------------------------------------------------------------
-----
Go to URL/ Details: Save up to 70.2 KB, 4 requests, 1 DNS lookups
Combine external JavaScript
There are 2 JavaScript files served from www.techwood.sk. They should be 
combined
into as few files as possible:

    * Go to URLhttp://www.techwood.sk/shared/min/?g=js
    * Go to URLhttp://www.techwood.sk/shared/min/g=js 

Serve resources from a consistent URL
The following resources have identical contents, but are served from different 
URLs.
Serve these resources from a consistent URL to save 4.19 KB and 1 requests:

    * Go to URLhttp://www.techwood.sk/shared/min/?g=css
    * Go to URLhttp://www.techwood.sk/shared/min/g=css 

The following resources have identical contents, but are served from different 
URLs.
Serve these resources from a consistent URL to save 52.4 KB and 1 requests:

    * Go to URLhttp://www.techwood.sk/shared/min/?g=js
    * Go to URLhttp://www.techwood.sk/shared/min/g=js 

Combine external CSS
There are 2 CSS files served from www.techwood.sk. They should be combined into 
as
few files as possible:

    * Go to URLhttp://www.techwood.sk/shared/min/?g=css
    * Go to URLhttp://www.techwood.sk/shared/min/g=css 
--------------------------------------------------------------------------------
-----
What is wrong????
Help me pls!

my site: www.techwood.sk
/shared/min/.htaccess:
--------------------------------------------------------------------------------
-----
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /shared/min
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
</IfModule> 
--------------------------------------------------------------------------------
-----
Including JS, CSS:
--------------------------------------------------------------------------------
-----
<link type="text/css" rel="stylesheet" 
href="{$settings->getWebShared()}/min/g=css" />
<script type="text/javascript" 
src="{$settings->getWebShared()}/min/g=js"></script>
--------------------------------------------------------------------------------
-----

Original comment by repcikju...@gmail.com on 20 Jan 2010 at 9:04

GoogleCodeExporter commented 9 years ago
@repcikjuraj The tool is simply wrong. These tools aren't perfect and you can 
clearly
verify there is only 1 request each for Minify's JS/CSS. I recommend 
smaller/fewer
images, and spreading them across a couple subdomains. Even AS IS the page only 
takes
about 1.5s to complete on my end and, once cached, it's super quick.

Original comment by mrclay....@gmail.com on 20 Jan 2010 at 1:40

GoogleCodeExporter commented 9 years ago
@mrclay.org, maybe I found the reason.
1. Slow loading - I had switched "Autorun YSlow each time a web page is loaded" 
and
when I debug page I used Yslow and PageSpeed often. So it was maybe the reason -
/beacon/yslow/?. 
2. Doubled adrresses - old address was maybe just in google cache, because now 
its OK.

Original comment by repcikju...@gmail.com on 26 Jan 2010 at 11:48

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 3 Sep 2011 at 11:47