SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist DMacedo's Avatar
    Join Date
    May 2004
    Location
    Braga, Portugal
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy mod_rewrite w/an array of options

    Now this is turning my head around and I am way too tired to solve it.

    I have been trying to use an array in mod_rewrite, but cannot seem to find a way do it...
    So what do I mean with this? I have this rule:

    RewriteRule ^([a-zA-Z]{2})/(index|whatisthis|anotherone|...)?$ /$2.php?language=$1 [QSA,L]

    As you should plainly see this will turn:
    /pt/index -turns-into-> /index.php?language=pt
    /es/whatisthis -turns-into-> /whatisthis.php?language=es
    /en/anotherone -turns-into-> /anotherone.php?language=en

    Now what I need to accomplish is making this work in "language aware" mode:
    /pt/queeisto -turns-into-> /whatisthis.php?language=pt
    /es/unomas -turns-into-> /anotherone.php?language=es

    Meaning translated versions will work as a KEY for it's english value. This web site has 20 languages and around 50 .php (including other sub-dirs in other rules) so I really need to make it work this way in htaccess, I cannot simply redirect everything...

    And I am too tired after 14 hours of work to find this out on my own, but I hope I made myself clear enough so someone can help out

    Does anyone know a way I can do this?
    ~ Daniel Macedo

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    DM,

    You've actually created your "array" rule correctly. Please remember that Apache is a server so the people who were kind enough to create the module to rewrite REQUEST_URIs didn't make it as powerful as PHP/Perl's regex.

    There is a rewrite_map module which will allow you to do mapping of pages but I have to ask why you'd want to do that - do you really rename your scripts so that visitors can type them all in? Of course not, your Home page will provide the links to all the other pages! That said, I don't see the use of what you term a "language aware" mode (I call it a "translation mode") when you're controlling the script names and can add the correct translation in the link's title or status bar info. Of course, that's from someone too dumb to learn even a second language (other than as "spoken" by computers) despite three attempts in the academic world.

    Where mod_rewrite should be able to help is in reading the server variable that identifies the language(s) accepted by the visitor's browser (off the top, I don't know what that variable's name is).

    Lastly, you DON'T need the QSA flag unless you're passing along other information which might be embedded in the REQUEST_URI string.

    I hope that at least some of this helped.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Evangelist DMacedo's Avatar
    Join Date
    May 2004
    Location
    Braga, Portugal
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't the qsappend flag required in order to also pass the query string to the rewriten URI (i.e. /pt/index?some=var passed to the rewritten URI)?

    In this particular case, it is important that the URI is human-readable. And not only that but language aware... So this is extra work and headache for no extra money at all!

    I actually didn't knew the rewrite_map module which also has the advantage of being able to be included in the CMS (with a few more nights of work), I am sure it can use a php script (my perl is somewhat rusty, plus the CMS is all in php anyway) and I take advantage of all the users info already in the database, etc.

    But for today, business is closed, and it is time for Silence to take over!
    Thank you and good night (I'm sorry, good afternoon in your case )
    ~ Daniel Macedo

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    DM,

    The QSA flag is to passthrough a pre-existing query string. It is NOT needed to create a new query string via mod_rewrite (common error I'm seeing lately).

    Bummer about the "human readable" but that's what my suggestion was supposed to do - BEFORE the visitor clicks on the link. A TITLE for the anchor (link) will pop-up a small box which PHP can write in the language selected by the query string's variable.

    I don't have a need to use rewrite_maps so color me ignorant - I just know that it's available. Someday, I'll find the time to investigate.

    Good night to you, too!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •