Cache obrázkov a RewriteRule

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
romiix.org
Člen | 343
+
0
-

Zdravím,
naväzujem na https://forum.nette.org/…ledy-obrazku#….
Ako má prosím vyzerať .htaccess ak chcem, aby:
sa obrázky ťahali z www/thumb/<nazov-obrazka>.<typ-obrazka>.png napr. www/thumb/obrazok.small.png
a v prípade ak obrázok neexistuje, by sa ťahal z /www/images/?file=<nazov-obrazka>.png&type=<typ-obrazka> napr. /www/images/?file=obrazok.png&type=small

Použil som teraz

RewriteCond %{REQUEST_URI} ^/thumb/([^.]+)\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /images/?file=%1.%2 [NE,L]

ale neráta to s typmi obrázkov:(

Ďakujem za každý námet.

voda
Člen | 561
+
0
-

Zkus to s tímhle:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ images/?file=$1.$3&type=$2 [NE,L]
romiix.org
Člen | 343
+
0
-

ak zadám do prehliadača www/thumb/obrazovka.small.png tak mi vyskočí ladenka s hláškou „No route for HTTP request.“, pričom www/images/?file=obrazovka.png&type=small normálne funguje.
dá sa nejak zistiť, na akú presnú stránku to reálne presmerovalo?
Resp. v čom môže byť chyba?

Vďaka

newPOPE
Člen | 648
+
0
-

Pozeral som vlakno na ktore odkazujes ale len ryyychlo :-).

Ja osobne to riesim tak ako Drupal a jeho imagecache.

  1. Ak je request napr na /files/image-cache/<preset>/<cesta k obrazku>
  2. neexistuje cize to odchyti app, vygenerujem a ulozim do WWW_DIR/files/image-cache/<preset>/<cesta k obrazku>
  3. existuje tak sa to odchyti na urovni pred app a taha si to rovno browser, co sa mi zda najrychlejsie :-)
  4. ak potrebujes este nejaky preprocess pred zobrazenim obrazka, prava atd… tak tento sposob nie je dobry. ak su obrazky public tak sa mi zda celkom OK

Ak to nie je co potrebujes tak sorry, cital som rychlo :-)

voda
Člen | 561
+
0
-
  1. Kam ti směřuje documentRoot?
  2. Jakou url k aplikaci přistupuješ?
  3. Kde máš uložen .htacces soubor?
  4. Jak máš nastaven RewriteBase v .htaccess?
romiix.org
Člen | 343
+
0
-
  1. Kam ti směřuje documentRoot?

http://localhost/cms/www/

  1. Jakou url k aplikaci přistupuješ?

http://localhost/cms/www/images/?…
http://localhost/…ka.small.png

  1. Kde máš uložen .htacces soubor?

v priečinku /opt/lampp/htdocs/cms/www

  1. Jak máš nastaven RewriteBase v .htaccess?
# disable directory listing
Options -Indexes

# mod_rewrite
<IfModule mod_rewrite.c>
	RewriteEngine On
	# RewriteBase /

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ images/?file=$1.$3&type=$2 [NE,L]

	# front controller
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]
</IfModule>
voda
Člen | 561
+
0
-

Nastav RewriteBase /cms/www.

romiix.org
Člen | 343
+
0
-

voda napsal(a):

Nastav RewriteBase /cms/www.

Skúsil som to a správalo sa to presne tak isto :(

prišiel som na toto:
ak zmením rewrite na RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ /NRomiixCMS/www/clanok [NE,L] tak to robí to isté „no route“ atď

ale ak to dám napríklad na RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ /NRomiixCMS/www/js [NE,L] (existujúci priečinok) tak to naň presmeruje

Editoval romiix.org (23. 3. 2011 21:20)

voda
Člen | 561
+
0
-

A máš v www adresář images a v něm nějaký skript (index.php)? Nebo co se děje s tou výslednou (images/?file…) cestou?

romiix.org
Člen | 343
+
0
-

voda napsal(a):

A máš v www adresář images a v něm nějaký skript (index.php)? Nebo co se děje s tou výslednou (images/?file…) cestou?

Veď to práve nechápem a neviem ako to diagnostikovať.
Priečinok images nemám. Mám priečinok image, práve pri ňom som zistil, že redirect funguje ak sa to presmeruje na existujúci priečinok. Napr.:

RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ /cms/www/image/background.jpg [L]

funguje, lebo /cms/www/image/background.jpg existuje.

RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ /cms/www/clanok/ponuka [L]

zlyhá s hláškou „no route“, napriek tomu, že ak zadám do prehliadača http://localhost/cms/www/clanok/ponuka tak adresa normálne existuje.

Pripájam Debug::dump($_SERVER), možno to niečo objasní. Ja som chybu nenašiel.

1. Po zadaní http://localhost/cms/www/clanok/ponuka

array(32) {
   "REDIRECT_UNIQUE_ID" => "TYrkAn8AAQEAAEjiZHAAAAAE" (24)
   "REDIRECT_STATUS" => "200" (3)
   "UNIQUE_ID" => "TYrkAn8AAQEAAEjiZHAAAAAE" (24)
   "HTTP_HOST" => "localhost" (9)
   "HTTP_CONNECTION" => "keep-alive" (10)
   "HTTP_REFERER" => "http://localhost/cms/www/default/" (40)
   "HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.16 Safari/534.24" (101)
   "HTTP_ACCEPT" => "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" (90)
   "HTTP_ACCEPT_ENCODING" => "gzip,deflate,sdch" (17)
   "HTTP_ACCEPT_LANGUAGE" => "sk-SK,sk;q=0.8,cs;q=0.6,en-US;q=0.4,en;q=0.2" (44)
   "HTTP_ACCEPT_CHARSET" => "windows-1250,utf-8;q=0.7,*;q=0.3" (32)
   "HTTP_COOKIE" => "nette-debug-bar=0:0; nette-debug-panel-errors=-215:-61; PHPSESSID=fedrbtqhq481899g8f4h70guk7; nette-browser=cjzfar09mv" (118)
   "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" (75)
   "SERVER_SIGNATURE" => "<address>Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost  ... " (168)
   "SERVER_SOFTWARE" => "Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1" (120)
   "SERVER_NAME" => "localhost" (9)
   "SERVER_ADDR" => "127.0.0.1" (9)
   "SERVER_PORT" => "80" (2)
   "REMOTE_ADDR" => "127.0.0.1" (9)
   "DOCUMENT_ROOT" => "/opt/lampp/htdocs" (17)
   "SERVER_ADMIN" => "you@example.com" (15)
   "SCRIPT_FILENAME" => "/opt/lampp/htdocs/cms/www/index.php" (42)
   "REMOTE_PORT" => "32868" (5)
   "REDIRECT_URL" => "/cms/www/clanok/ponuka" (29)
   "GATEWAY_INTERFACE" => "CGI/1.1" (7)
   "SERVER_PROTOCOL" => "HTTP/1.1" (8)
   "REQUEST_METHOD" => "GET" (3)
   "QUERY_STRING" => ""
   "REQUEST_URI" => "/cms/www/clanok/ponuka" (29)
   "SCRIPT_NAME" => "/cms/www/index.php" (25)
   "PHP_SELF" => "/cms/www/index.php" (25)
   "REQUEST_TIME" => 1300947970
}

2. Po zadaní http://localhost/cms/www/thumb/obrazok.small.png
S rewriterule: RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ /cms/www/clanok/ponuka [L]

array(33) {
   "REDIRECT_REDIRECT_UNIQUE_ID" => "TYrnP38AAQEAAEkJ3m4AAAAJ" (24)
   "REDIRECT_REDIRECT_STATUS" => "200" (3)
   "REDIRECT_UNIQUE_ID" => "TYrnP38AAQEAAEkJ3m4AAAAJ" (24)
   "REDIRECT_STATUS" => "200" (3)
   "UNIQUE_ID" => "TYrnP38AAQEAAEkJ3m4AAAAJ" (24)
   "HTTP_HOST" => "localhost" (9)
   "HTTP_CONNECTION" => "keep-alive" (10)
   "HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.16 Safari/534.24" (101)
   "HTTP_ACCEPT" => "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" (90)
   "HTTP_ACCEPT_ENCODING" => "gzip,deflate,sdch" (17)
   "HTTP_ACCEPT_LANGUAGE" => "sk-SK,sk;q=0.8,cs;q=0.6,en-US;q=0.4,en;q=0.2" (44)
   "HTTP_ACCEPT_CHARSET" => "windows-1250,utf-8;q=0.7,*;q=0.3" (32)
   "HTTP_COOKIE" => "nette-debug-bar=0:0; nette-debug-panel-errors=-215:-61; PHPSESSID=fedrbtqhq481899g8f4h70guk7; nette-browser=cjzfar09mv" (118)
   "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" (75)
   "SERVER_SIGNATURE" => "<address>Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost  ... " (168)
   "SERVER_SOFTWARE" => "Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1" (120)
   "SERVER_NAME" => "localhost" (9)
   "SERVER_ADDR" => "127.0.0.1" (9)
   "SERVER_PORT" => "80" (2)
   "REMOTE_ADDR" => "127.0.0.1" (9)
   "DOCUMENT_ROOT" => "/opt/lampp/htdocs" (17)
   "SERVER_ADMIN" => "you@example.com" (15)
   "SCRIPT_FILENAME" => "/opt/lampp/htdocs/cms/www/index.php" (42)
   "REMOTE_PORT" => "34553" (5)
   "REDIRECT_URL" => "/cms/www/clanok/ponuka" (29)
   "GATEWAY_INTERFACE" => "CGI/1.1" (7)
   "SERVER_PROTOCOL" => "HTTP/1.1" (8)
   "REQUEST_METHOD" => "GET" (3)
   "QUERY_STRING" => ""
   "REQUEST_URI" => "/cms/www/thumb/obrazok.small.png" (39)
   "SCRIPT_NAME" => "/cms/www/index.php" (25)
   "PHP_SELF" => "/cms/www/index.php" (25)
   "REQUEST_TIME" => 1300948799
}

3. Po zadaní http://localhost/cms/www/thumb/obrazok.small.png
S rewriterule: RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ images/?file=$1.$3&type=$2 [NE,L]

array(35) {
   "REDIRECT_REDIRECT_UNIQUE_ID" => "TYrn5H8AAQEAAC@u1CYAAAAA" (24)
   "REDIRECT_REDIRECT_STATUS" => "200" (3)
   "REDIRECT_UNIQUE_ID" => "TYrn5H8AAQEAAC@u1CYAAAAA" (24)
   "REDIRECT_STATUS" => "200" (3)
   "UNIQUE_ID" => "TYrn5H8AAQEAAC@u1CYAAAAA" (24)
   "HTTP_HOST" => "localhost" (9)
   "HTTP_CONNECTION" => "keep-alive" (10)
   "HTTP_CACHE_CONTROL" => "max-age=0" (9)
   "HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.16 Safari/534.24" (101)
   "HTTP_ACCEPT" => "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" (90)
   "HTTP_ACCEPT_ENCODING" => "gzip,deflate,sdch" (17)
   "HTTP_ACCEPT_LANGUAGE" => "sk-SK,sk;q=0.8,cs;q=0.6,en-US;q=0.4,en;q=0.2" (44)
   "HTTP_ACCEPT_CHARSET" => "windows-1250,utf-8;q=0.7,*;q=0.3" (32)
   "HTTP_COOKIE" => "nette-debug-bar=0:0; nette-debug-panel-errors=-215:-61; PHPSESSID=fedrbtqhq481899g8f4h70guk7; nette-browser=cjzfar09mv" (118)
   "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" (75)
   "SERVER_SIGNATURE" => "<address>Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost  ... " (168)
   "SERVER_SOFTWARE" => "Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1" (120)
   "SERVER_NAME" => "localhost" (9)
   "SERVER_ADDR" => "127.0.0.1" (9)
   "SERVER_PORT" => "80" (2)
   "REMOTE_ADDR" => "127.0.0.1" (9)
   "DOCUMENT_ROOT" => "/opt/lampp/htdocs" (17)
   "SERVER_ADMIN" => "you@example.com" (15)
   "SCRIPT_FILENAME" => "/opt/lampp/htdocs/cms/www/index.php" (42)
   "REMOTE_PORT" => "60054" (5)
   "REDIRECT_QUERY_STRING" => "file=obrazok.png&type=small" (27)
   "REDIRECT_URL" => "/cms/www/images/" (23)
   "GATEWAY_INTERFACE" => "CGI/1.1" (7)
   "SERVER_PROTOCOL" => "HTTP/1.1" (8)
   "REQUEST_METHOD" => "GET" (3)
   "QUERY_STRING" => "file=obrazok.png&type=small" (27)
   "REQUEST_URI" => "/cms/www/thumb/obrazok.small.png" (39)
   "SCRIPT_NAME" => "/cms/www/index.php" (25)
   "PHP_SELF" => "/cms/www/index.php" (25)
   "REQUEST_TIME" => 1300948964
}

Som už z toho zúfalý.
Vďaka za hocakú pomoc!!

romiix.org
Člen | 343
+
0
-

Takže, konečne to funguje, aj keď nie ideálne.

RewriteRule ^thumb/([^.]+)\.([^.]+)\.(jpg|jpeg|png|gif)$ http://localhost/cms/www/images/?file=$1.$3&type=$2 [NE,L]

robí čo má. Nepríjemné je, že tam musí byť absolútna adresa – pri nahratí na ostrý server budem musieť prepisovať .htaccess.
Ak niekoho napadá ako to obísť, poteší.

Ďakujem všetkým ktorí pomáhali.