Twoje PC  
Zarejestruj się na Twoje PC
TwojePC.pl | PC | Komputery, nowe technologie, recenzje, testy
B O A R D
   » Board
 » Zadaj pytanie
 » Archiwum
 » Szukaj
 » Stylizacja

 
M E N U
  0
 » Nowości
0
 » Archiwum
0
 » Recenzje / Testy
0
 » Board
0
 » Rejestracja
0
0
 
Szukaj @ TwojePC
 

w Newsach i na Boardzie
 
OBECNI NA TPC
 
 » patinka 11:44
 » Wedrowiec 11:40
 » Dhoine 11:36
 » JE Jacaw 11:36
 » Demo 11:35
 » PaKu 11:34
 » steve 11:33
 » DYD 11:31
 » Sherif 11:31
 » maddog 11:30
 » jenot 11:28
 » petropank 11:27
 » Soulburne 11:27
 » Artaa 11:26
 » rurecznik 11:24
 » bajbusek 11:21
 » yeger 11:20
 » emigrus 11:19
 » Zic 11:19
 » Sebek 11:17

 Dzisiaj przeczytano
 41105 postów,
 wczoraj 25974

 Szybkie ładowanie
 jest:
włączone.

 
ccc
TwojePC.pl © 2001 - 2024
A R C H I W A L N A   W I A D O M O Ś Ć
    

[regex] pomocy z regułą w .htaccess , Tomasz 30/07/11 16:15
W pliku .htaccess mam regułę

RewriteRule ^(.*)\.[^.][\d]+\.(css|js)$ $1.$2 [L]

która służy do wycinania z nazwy pliku http://example.com/style.12345678.css części 12345678 dając w wyniku http://example.com/style.css

Reguła sama w sobie jest dobra, testowana tutaj http://www.regexplanet.com/simple/index.html - działa.

Serwer na którym testuję http://ccs.nazwa.pl/ - jeśli wejdziesz wyświetli się phpinfo().
Tu zaczyna się problem bo serwer zwraza ciąg oryginalny, nie obrobiony reguła. Inne reguły w .htacces działają dobrze a nie mają wpływu na tą, bo szukają innych ciągów.
Pomysł zaczerpnięty ze strony http://stackoverflow.com/...rule-not-picking-up-pa

Cały plik .htaccess

# URL rewriting module activation
RewriteEngine on

# Allow versioning for js and css files
RewriteRule ^(.*)\.[^.][\d]+\.(css|js)$ $1.$2 [L,E]
# End Allow versioning for js and css files

# URL rewriting rules
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2$3.jpg [L,E]
RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/c/$1$2.jpg [L,E]
RewriteRule ^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$3&isolang=$1$5 [L,E]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2&isolang=$1$4 [L,E]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$2&isolang=$1 [QSA,L,E]
RewriteRule ^([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$2$4 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /product.php?id_product=$1$3 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /category.php?id_category=$1 [QSA,L,E]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /cms.php?id_cms=$1 [QSA,L,E]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*)(.*)$ /supplier.php?id_supplier=$1$3 [QSA,L,E]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*)(.*)$ /manufacturer.php?id_manufacturer=$1$3 [QSA,L,E]
RewriteRule ^lang-([a-z]{2})/(.*)$ /$2?isolang=$1 [QSA,L,E]

# Catch 404 errors
ErrorDocument 404 /404.php

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

https://www.siepomaga.pl/milosz-mosko

  1. A nie lepiej... , Kilgor-Admin 30/07/11 16:59
    ... style.css?ver=2011073001

    Pozdr. Kilgor
    Admin Board'a

    1. prościej tak, lepiej chyba nie , Tomasz 30/07/11 17:08
      rozwiązanie z rewrite jest przeźroczyste dla klienta z parametrami GET nie. Tutaj dyskutowali o tym http://stackoverflow.com/...ad-cached-css-js-files

      Rozwiązanie rewrite na pewno zadziała bez względu czy klient cache'uje wywołania z ?ver czy nie.

      https://www.siepomaga.pl/milosz-mosko

  2. dla wszystkich tych, którzy nie rozumieją RegEx a chcieliby , Tomasz 30/07/11 19:08
    urozmaicić sobie sobotni wieczór małą łamigłówką, oto opis jak rozszyfrować RegExa z pierwszego RewriteRule'a

    # the # instructs the server to ignore the line. used for including comments. each line of comments requires it&#8217;s own #. when including comments, it is good practice to use only letters, numbers, dashes, and underscores. this practice will help eliminate/avoid potential server parsing errors.
    [F] Forbidden: instructs the server to return a 403 Forbidden to the client.
    [L] Last rule: instructs the server to stop rewriting after the preceding directive is processed.
    [N] Next: instructs Apache to rerun the rewrite rule until all rewriting directives have been achieved.
    [G] Gone: instructs the server to deliver Gone (no longer exists) status message.
    [P] Proxy: instructs server to handle requests by mod_proxy
    [C] Chain: instructs server to chain the current rule with the previous rule.
    [R] Redirect: instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL.
    [NC] No Case: defines any associated argument as case-insensitive. i.e., "NC" = "No Case".
    [PT] Pass Through: instructs mod_rewrite to pass the rewritten URL back to Apache for further processing.
    [OR] Or: specifies a logical "or" that ties two expressions together such that either one proving true will cause the associated rule to be applied.
    [NE] No Escape: instructs the server to parse output without escaping characters.
    [NS] No Subrequest: instructs the server to skip the directive if internal sub-request.
    [QSA] Append Query String: directs server to add the query string to the end of the expression (URL).
    [S=x] Skip: instructs the server to skip the next "x" number of rules if a match is detected.
    [E=variable:value] Environmental Variable: instructs the server to set the environmental variable "variable" to "value".
    [T=MIME-type] Mime Type: declares the mime type of the target resource.
    [] specifies a character class, in which any character within the brackets will be a match. e.g., [xyz] will match either an x, y, or z.
    []+ character class in which any combination of items within the brackets will be a match. e.g., [xyz]+ will match any number of x&#8217;s, y&#8217;s, z&#8217;s, or any combination of these characters.
    [^] specifies not within a character class. e.g., [^xyz] will match any character that is neither x, y, nor z.
    [a-z] a dash (-) between two characters within a character class ([]) denotes the range of characters between them. e.g., [a-zA-Z] matches all lowercase and uppercase letters from a to z.
    a{n} specifies an exact number, n, of the preceding character. e.g., x{3} matches exactly three x&#8217;s.
    a{n,} specifies n or more of the preceding character. e.g., x{3,} matches three or more x&#8217;s.
    a{n,m} specifies a range of numbers, between n and m, of the preceding character. e.g., x{3,7} matches three, four, five, six, or seven x&#8217;s.
    () used to group characters together, thereby considering them as a single unit. e.g., (perishable)?press will match press, with or without the perishable prefix.
    ^ denotes the beginning of a regex (regex = regular expression) test string. i.e., begin argument with the proceeding character.
    $ denotes the end of a regex (regex = regular expression) test string. i.e., end argument with the previous character.
    ? declares as optional the preceding character. e.g., monzas? will match monza or monzas, while mon(za)? will match either mon or monza. i.e., x? matches zero or one of x.
    ! declares negation. e.g., &#8220;!string&#8221; matches everything except &#8220;string&#8221;.
    . a dot (or period) indicates any single arbitrary character.
    - instructs &#8220;not to&#8221; rewrite the URL, as in &#8220;...domain.com.* - [F]&#8221;.
    + matches one or more of the preceding character. e.g., G+ matches one or more G&#8217;s, while "+" will match one or more characters of any kind.
    * matches zero or more of the preceding character. e.g., use &#8220;.*&#8221; as a wildcard.
    | declares a logical &#8220;or&#8221; operator. for example, (x|y) matches x or y.
    \ escapes special characters ( ^ $ ! . * | ). e.g., use &#8220;\.&#8221; to indicate/escape a literal dot.
    \. indicates a literal dot (escaped).
    /* zero or more slashes.
    .* zero or more arbitrary characters.
    ^$ defines an empty string.
    ^.*$ the standard pattern for matching everything.
    [^/.] defines one character that is neither a slash nor a dot.
    [^/.]+ defines any number of characters which contains neither slash nor dot.
    http:// this is a literal statement &#8212; in this case, the literal character string, &#8220;http://&#8221;.
    ^domain.* defines a string that begins with the term &#8220;domain&#8221;, which then may be proceeded by any number of any characters.
    ^domain\.com$ defines the exact string &#8220;domain.com&#8221;.
    -d tests if string is an existing directory
    -f tests if string is an existing file
    -s tests if file in test string has a non-zero value

    Pozostałe reguły działają ale jeśli ktoś chce może je też sobie rozpisać, myślę że trudno się oprzeć takiej pokusie.

    https://www.siepomaga.pl/milosz-mosko

  3. [solved] , Tomasz 31/07/11 20:45
    Reguła, która działa

    RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /(.*)\.[^.][0-9]+\.(css|js).*\ HTTP/ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .+ %2.%3 [NC,L]

    Rozwiązane dzięki informacją zawartym na stronie http://www.askapache.com/...ing-updated-files.html

    BTW jedno z lepszych źródeł informacji jakie do tej pory widziałem, potwierdziło się moje podejrzenia że lepiej nie stosować style.css?foo=bar

    https://www.siepomaga.pl/milosz-mosko

    
All rights reserved ® Copyright and Design 2001-2024, TwojePC.PL