Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mod Rewrite help after 9 variables please

    So I have my conf file as so:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    ##### GENERIC RULES #####
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/?$ index.php?$1=$2 [L]
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4 [L]
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6 [L]
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6&$7=$8 [L]
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L]
    
    RewriteCond %{REQUEST_URI} !\.(css|php|png|jpg|gif|ico|js|inc|txt|gz|xml|html)$
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6&$7=$8&9=$10&$11=$12 [L]
    I've read that this is the worst way to go about doing what I want. Basically I want the get data to have slashes between it.

    For example: index.php?action=hi&page=4&config=no
    would turn into: /action/hi/page/4/config/no/

    I can get it working all the way until I have to use 10 and up variables. I know that it's made to only use 9 variables, but what am I suppose to do if I need 10? Is there a way to make the above config into some type of loop? I hope you understand what I'm asking, and maybe someone can post a working version of what I have? Thanks

  • #2
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by pankirk View Post
    So I have my conf file as so:

    ...
    {SNIP FOR CLARITY}
    I've got to ask the million dollar question - and forgive me - but, why do you need to convert that querystring using mod_rewrite? What is wrong with using the .php to do it and redirect based on that?

    I'm guessing either some SEO or conversion of existing site may be the issue here, but you don't have to rely on mod_rewrite kludge to do this.

    If it were the other way round and I was entering the URL: http://www.site.com/this/that/the/ot...all/that/stuff and wanted to grab what was in the slashes and convert it to a querystring, I could understand the need. But the other way round I'd let php do the heavy lifting and place no dependence on the server software/modules.
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because I have my code setup that it pulls information from $_GET on the index.php file then includes the appropriate page information based upon what is in the url.

    For example,

    For example: index.php?page=account&view=support&sub=all&id=1

    If you look at it, you can tell that I will have a bunch of switch statements which output data according to what is set.

    That url would be showing me the "account page" and I would be viewing a "support inquire" with the id of 1. All which is nested inside the account page.

    I don't want the url to look like how it does because it looks ridiculous and unprofessional.

  • #4
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by pankirk View Post
    Because I have my code setup that it pulls information from $_GET on the index.php file then includes the appropriate page information based upon what is in the url.

    For example,

    For example: index.php?page=account&view=support&sub=all&id=1

    If you look at it, you can tell that I will have a bunch of switch statements which output data according to what is set.
    Why? I don't see a single switch here and it more or less does all you want without caring how many querystring pairs there are:

    PHP Code:
    <?php 
    //
    $final_url="index.php";
    foreach(
    $_GET as $key => $value) {
    $_GET[$key] = trim($value);
    $getarray["$key"] = $_GET[$key];
    }
    if (!empty(
    $getarray)) {
        
    $final_url.="/";
        foreach (
    $getarray as $key => $value) {
        
    $final_url.=$key."/".$value."/";
        }
    $final_url rtrim($final_url"/");
    }
    echo 
    "DEBUG - YOUR FINAL URL IS:" .$final_url."\n";
    // header("Location: ".$final_url); //replace the above echo with this
    ?>
    {caveat - only lightly tested}

    EDIT - SEE POST BELOW
    Last edited by 120; 10-20-2010 at 09:29 PM.
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot

  • #5
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    I think what you've said has come out back to front to me:

    For example: index.php?action=hi&page=4&config=no
    would turn into: /action/hi/page/4/config/no/
    I've taken that literally as you've written it, but I suspect you actually mean is when a user types:
    mysite.com/this/that/something/else you want to translate that to a querystring such as mysite.com?this=that&some=thing&else=here;
    (looking at your mod_rewrite it's glaringly obvious what you are trying to do - just what you've written inverts it)

    [EDIT]
    DELETED - HAVING BLONDE MOMENT

    I'll see if I can find the details on the recursive re-reading I kept.
    Last edited by 120; 10-21-2010 at 06:04 AM.
    There is always plenty of idol work for the devils hands to do
    Registered Linux User 475075 : Project Honeypot


  •  

    Posting Permissions

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