tomharto 02-19-2011, 08:25 AM "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 =[
oesxyl 02-19-2011, 09:26 PM "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/mod_rewrite.html#rewritecond
best regards
tomharto 02-20-2011, 02:42 AM I meant rewrite unless the word is either includes or pages, i got around that by putting
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
RewriteRule ^games/([^/\.]+)$ index.php?page=games&game=$1 [L] but that didnt work, can anyone help?
oesxyl 02-20-2011, 03:44 AM I meant rewrite unless the word is either includes or pages, i got around that by putting
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
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:
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?
i forget, maybe this will help you:
how it work http://httpd.apache.org/docs/2.2/rewrite/rewrite_tech.html#InternalRuleset
how you can debug if you have access to the server config http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
best regards
tomharto 02-20-2011, 12:57 PM 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
oesxyl 02-20-2011, 02:06 PM 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?
RewriteRule ^(pages|includes)$ $1 [L]
RewriteRule ^games\/game(.*)$ index.php?page=$1 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
best regards
tomharto 02-20-2011, 03:09 PM That seems to work great thanks :). Could you explain it so hopefully i can adapt it if needed rather than making a new post?
oesxyl 02-20-2011, 03:59 PM 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:
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
RewriteRule ^games\/game(.*)$ index.php?page=$1 [L]
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
tomharto 02-20-2011, 05:21 PM Thanks a lot :). On further testing the code you put didn't work but thanks to your explanation i got it working
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 :)
oesxyl 02-20-2011, 07:07 PM 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, :)
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?
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
|
|