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 10 of 10

Thread: Rewrite unless

  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Rewrite unless

    "RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]"

    I need to add a line saying do that rule unless $1 is either pages or includes, how do i go about doing that? Ive had a look around but cant find a result =[

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomharto View Post
    "RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]"

    I need to add a line saying do that rule unless $1 is either pages or includes, how do i go about doing that? Ive had a look around but cant find a result =[
    i suspect you can use RewriteCond but i don't understand what do you mean by "is either pages or includes".
    once you make clear what is 'pages' and 'includes' you can simulate the 'or' by using RewriteCond twice, once for each condition.

    http://httpd.apache.org/docs/2.2/mod...ml#rewritecond

    best regards

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    I meant rewrite unless the word is either includes or pages, i got around that by putting
    Code:
    RewriteRule ^pages - [L]
    RewriteRule ^includes - [L]
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]
    however i need now a line to say "If link is games/game1 rewrite to index.php?page=games&game=$1" but i cant figure it out. I tried
    Code:
    RewriteRule ^games/([^/\.]+)$ index.php?page=games&game=$1 [L]
    but that didnt work, can anyone help?

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomharto View Post
    I meant rewrite unless the word is either includes or pages, i got around that by putting
    Code:
    RewriteRule ^pages - [L]
    RewriteRule ^includes - [L]
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]
    however i need now a line to say "If link is games/game1 rewrite to index.php?page=games&game=$1" but i cant figure it out. I tried
    Code:
    RewriteRule ^games/([^/\.]+)$ index.php?page=games&game=$1 [L]
    but that didnt work, can anyone help?
    no, is wrong, i said, RewriteCond not RewriteRule, see the link from my previous replay about how to use RewriteCond.
    that means something like this:
    Code:
    RewriteCond pages....
    RewriteCond includes...
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]
    if one of the RewriteCond is match then the first rule is apply else will check for the next RewriteCond, that means an or between both RewriteCond.
    I'm still unclear how you want to check for 'pages' and 'includes', where the words must be, in url?

    Edit: i forget, maybe this will help you:
    how it work http://httpd.apache.org/docs/2.2/rew...nternalRuleset
    how you can debug if you have access to the server config http://httpd.apache.org/docs/2.2/mod...tml#rewritelog


    best regards
    Last edited by oesxyl; 02-20-2011 at 04:49 AM.

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Ok ill look at rewritecond . The URLS would be like
    www.example.com/pages - dont rewrite
    www.example.com/includes - dont rewrite
    www.example.com/games/game1 - rewrite index.php?page=games&game=$1
    www.example.com/(any thing else) - rewrite index.php?page=$1

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomharto View Post
    Ok ill look at rewritecond . The URLS would be like
    www.example.com/pages - dont rewrite
    www.example.com/includes - dont rewrite
    www.example.com/games/game1 - rewrite index.php?page=games&game=$1
    www.example.com/(any thing else) - rewrite index.php?page=$1
    maybe i misunderstand what you want, this will work for you?
    Code:
    RewriteRule ^(pages|includes)$ $1 [L]
    RewriteRule ^games\/game(.*)$ index.php?page=$1 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    best regards

  • Users who have thanked oesxyl for this post:

    tomharto (02-20-2011)

  • #7
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    That seems to work great thanks . Could you explain it so hopefully i can adapt it if needed rather than making a new post?

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomharto View Post
    That seems to work great thanks . Could you explain it so hopefully i can adapt it if needed rather than making a new post?
    i'm glad it work and of course i explain,

    about [L] i guess you know, if the rule is matched then is the last one and skip everything else, if not continue with next rule

    now about each rule:
    Code:
    RewriteRule ^(pages|includes)$ $1 [L]
    () is the group, $1 is 1 because if first group, if you have more groups each from left to right will be referred as 1, 2, up to 9
    inside the group | is an 'or' that means 'pages' or 'includes' take it literaly

    Code:
    RewriteRule ^games\/game(.*)$ index.php?page=$1 [L]
    Code:
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    is nothing new here except .*, dot mean any char, star is zero or more. If you need one or more use plus, +, instead

    that is all i hope. Anyway if is something unclear just ask,

    best regards

  • Users who have thanked oesxyl for this post:

    tomharto (02-20-2011)

  • #9
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Thanks a lot . On further testing the code you put didn't work but thanks to your explanation i got it working

    Code:
    RewriteEngine on
    RewriteRule ^pages - [L]
    RewriteRule ^includes - [L]
    RewriteRule ^games/(.*)$ index.php?page=games&game=$1 [L]
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]
    I think when i did it i put the games one last, and i didn't know about the [L] so i guess that's why it wasnt working

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomharto View Post
    Thanks a lot . On further testing the code you put didn't work but thanks to your explanation i got it working
    probably i sould mention that i didn't test it, i'm glad i help you,

    Code:
    RewriteEngine on
    RewriteRule ^pages - [L]
    RewriteRule ^includes - [L]
    RewriteRule ^games/(.*)$ index.php?page=games&game=$1 [L]
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&func=$2 [L]
    I think when i did it i put the games one last, and i didn't know about the [L] so i guess that's why it wasnt working
    you have something after pages and includes? like in pagesbla?
    this don't work?
    Code:
    RewriteRule ^(pages|includes) - [L]
    i guess you know that $ in pattern means the end of the string, in previous rule i used $ to cut the string.

    best regards


  •  

    Posting Permissions

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