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 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Beginner help with modrewrite?

    I found this rule online which seems to work for all of my pages so far:

    Code:
    RewriteRule (.*)/(.*)/$ /index.php?$1=$2
    basically this takes my pages that look like this: url.com/index.php?page=index,

    and turns them into this: url.com/page/index/

    This is great and is exactly what i'm looking for, but I can't seem to figure out what to do when I have multiple arguments in the url.

    For example, if I have this: url.com/index.php?page=index&sub=subpage.

    can someone please direct me in the right direction to form that url into this: url.com/page/index/sub/subpage/

    thanks a lot!

  • #2
    New Coder
    Join Date
    Jan 2010
    Location
    UT
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You would simply need to add another rule for that.

    I've adjusted your first line so that its more specific on what it should accept and what to do with it because just using (.*) will match every character and any number of characters, which can sometimes give you undesirable results.

    Code:
    RewriteRule ^page/(.*)/sub/(.*)/$ /index.php?page=$1&sub=$2 [L]
    RewriteRule ^page/(.*)/$ /index.php?page=$1 [L]
    Just to go over it, the ^ character means that this is the start of the string. I put [L] at the end of both lines to tell apache that if the URL requested matches this, stop going through the rules and use this one.

    If you want to learn more about mod_rewrite, I posted a tutorial on my site about it (How to make SEO Friendly URLs using mod_rewrite). It explains some basics and has a list of each of the flags too.

    Lemme know if you need anymore help.


  •  

    Posting Permissions

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