Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2011, 08:25 AM   PM User | #1
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 794
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
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 =[
tomharto is offline   Reply With Quote
Old 02-19-2011, 09:26 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 02-20-2011, 02:42 AM   PM User | #3
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 794
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
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?
tomharto is offline   Reply With Quote
Old 02-20-2011, 03:44 AM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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 03:49 AM..
oesxyl is offline   Reply With Quote
Old 02-20-2011, 12:57 PM   PM User | #5
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 794
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
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
tomharto is offline   Reply With Quote
Old 02-20-2011, 02:06 PM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
tomharto (02-20-2011)
Old 02-20-2011, 03:09 PM   PM User | #7
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 794
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
That seems to work great thanks . Could you explain it so hopefully i can adapt it if needed rather than making a new post?
tomharto is offline   Reply With Quote
Old 02-20-2011, 03:59 PM   PM User | #8
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
tomharto (02-20-2011)
Old 02-20-2011, 05:21 PM   PM User | #9
tomharto
Regular Coder

 
Join Date: Jul 2010
Location: Sheffield
Posts: 794
Thanks: 91
Thanked 18 Times in 18 Posts
tomharto is on a distinguished road
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
tomharto is offline   Reply With Quote
Old 02-20-2011, 07:07 PM   PM User | #10
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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,

Quote:
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
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 AM.


Advertisement
Log in to turn off these ads.