Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    .htaccess RewriteRule oltre i 9 parametri...

    Ciao a tutti, sto provando a realizzare un RewriteRule per semplificare l'url di ricerca del sito...
    essendo una ricerca utilizza diversi valori di ricerca... oltre i 9.

    e mi sono accorto che RewriteRule, pare non gestirne oltre 9... è vero? si può aggirare il problema?

    Codice PHP:

    RewriteRule 
    ^ricerca/(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*)\-(\d*).htmltest.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5&var6=$6&var7=$7&var8=$8&var9=$9&var10=$10 
    la variabile 10...non viene mostrata. mostra la 1.. con in aggiunta lo 0... insomma non interpreta correttamente il valore 10.. lo vede come se fosse 1

  2. #2
    cercando...avrei trovato questo codice... che però non capisco minimamente... qualcuno sa spiegarmelo.. e se fa al caso mio ? :P

    DOMANDA
    Hi, gang. I'm trying to rewrite urls having optional parameters and multiple variable, of this type:
    http:// http://www.mysite.com/index.php?j1=1...j4=4&j5=5&j7=7...
    http:// http://www.mysite.com/index.php?j2=2...j5=5&j6=6&j7=7...

    The URL I want to show in browser is:
    http:// http://www.mysite.com/keyword/j1_1/j...5_5/j6_6/j7_7/...

    Obviously, with this many parameters I would eventually pass the limit of 9 mod_rewrite variables. So I was trying to "replace" strings inside URL. The rewrite code I came up with is:

    RewriteRule ^keyword([^/]+)?(/j1_([^/]+))?(.*)$ keyword$1&j1=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j2_([^/]+))?(.*)$ keyword$1&j2=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j3_([^/]+))?(.*)$ keyword$1&j3=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j4_([^/]+))?(.*)$ keyword$1&j4=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j5_([^/]+))?(.*)$ keyword$1&j5=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j6_([^/]+))?(.*)$ keyword$1&j6=$2$3 [nc]
    RewriteRule ^keyword([^/]+)?(/j7_([^/]+))?(.*)$ keyword$1&j7=$2$3 [nc]
    RewriteRule ^keyword([^/]+)? index.php?$1 [nc,l]

    No 404 or 500 error after implementing this above, but unfortunatelly there were no values for the variables in the rewritten URL:
    http:// http://www.mysite.com/index.php?&j1=...4=&j5=&j6=&j7=...

    If anyone figures out where the error is in the code, please help me out. Many thanks in advanced!

    RISPOSTA

    One thing that may help you debug this is to change the rule to an external redirect so you can see what is going on.Obvious problems are a missing slash and the use of $2, which contains the entire optional parameter on each line, e.g. "j1_124", when all you want is $3 which contains only "124".
    However, you may be running into a well-known Apache mod_rewrite bug [searchengineworld.com] that crops up when a URL-path is rewritten repeatedly. The result is that duplicate URL info is appended to the URL-path, which to use highly-technical terminology, "really messes things up."
    As a result, I'd suggest an alternate approach, using the "user-defined variable" method:

    # Skip following section if not a "keyword/" request
    RewriteRule !^keyword/ - [S=9]
    #
    # Else copy/append keywords to user-defined variable "tQuery"
    RewriteRule ^keyword(/[^/]+)*/j1_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}j1=$2]
    RewriteRule ^keyword(/[^/]+)*/j2_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j2=$2]
    RewriteRule ^keyword(/[^/]+)*/j3_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j3=$2]
    RewriteRule ^keyword(/[^/]+)*/j4_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j4=$2]
    RewriteRule ^keyword(/[^/]+)*/j5_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j5=$2]
    RewriteRule ^keyword(/[^/]+)*/j6_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j6=$2]
    RewriteRule ^keyword(/[^/]+)*/j7_([^/]+) - [NC,E=tQuery:%{ENV:tQuery}&j7=$2]
    #
    # Strip leading "&" from tQuery (if any)
    RewriteCond %{ENV:tQuery} ^&(.+)$
    RewriteRule ^keyword/ - [NC,E=tQuery:%1]
    #
    # Rewrite the URL-path to index.php query format
    # RewriteRule ^keyword/ /index.php?%{ENV:tQuery} [NC,L]
    #
    # Use the following rule for easier testing only, then un-comment the rule above and delete this one.
    RewriteRule ^keyword/ http://example.com/index.php?%{ENV:tQuery} [NC,R=301,L]

    Here, we leave the requested URL-path entirely unchanged while appending each keyword-path value onto a temporary query string variable "tQuery". Then at the end, we use the built-up tQuery variable as the new query string.

    The first rule is for efficiency only. It is entirely optional, but intended to improve performance if you add many more query parameters. It simply skips all the rules in this set if the URL does not start with "keyword/"
    I sure hope I typed everything correctly and didn't forget anything!
    Jim

  3. #3
    potreste spostare la discussione in "PHP", credo che forse sarebbe l'area più adatta... grazie

  4. #4
    RewriteCond %{REQUEST_URI} /(service_([A-Za-z0-9_]+))?(/.+)$
    RewriteRule ^tools/chart(/id_([^\/]+))?(/user_([A-Za-z0-9_]+))?(/action_([A-Za-z0-9_]+))?(/date_([A-Za-z0-9_]+))?(/service_([A-Za-z0-9_]+))?(/.+)$ my_php_file.php?id=$2&user=$4&action=$6&date=$8&se rvice=%2&message=%3




    anche qui...non capisco come funziona... ho provato a fare la stessa cosa ma non mi va... qualcuno sa spiegarmi?

  5. #5
    ho provato semplificando una cosa del tipo


    RewriteCond %{REQUEST_URI} ^ricerca\-(singola)/
    RewriteRule ^ricerca\-singola/prodotto\-(offerta|novita).html$ test.php?tipric=%1&vax=$1


    dall'esempio mi par di capire che RewriteCond permette di avere una serie di variabili con %


    ma a me non funziona nemmeno questa semplice prova...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.