Forum Moderators: phranque

Message Too Old, No Replies

rewriteRule to match two conditions

confused with two conditions

         

phparion

7:51 am on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I want to redirect the following pattern

www.example.com/whatever/

but I do not want to redirect when index.php or any other .php is written instead of whatever

i used the following rules

RewriteRule ^/[^\.](.+)/$ /show.php?page_url=$1 [L]

and

RewriteRule ^/^index\.php$(.+)/$ /show.php?page_url=$1 [L]

but both URLs dont catch the pattern.

please help, thank you.

phparion

8:35 am on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



with this

RewriteRule ^[^\.](.+)/$ /show.php?page_url=$1 [L] (removed first slash)

it has started to work but it is escaping the first character e.g

www.example.com/whatever/ sends me hatever and W is escaped. it happens for all values.

jdMorgan

1:35 pm on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your pattern isn't quite right. Try:

# Rewrite all requests which have no file extension
RewriteRule ^(([^/]/)*[^.]+)/$ /show.php?page_url=$1 [L] (removed first slash)

I'm taking you at your word that you expect requests for "/whatever/" and "whatever" could be "xyz.php", making the requested URL-path look like "/xyz.php/" (with a trailing slash). If you don't really need to cover that contingency, then a simpler pattern will do:

# Rewrite requests for all "pages" requested with trailing slash
RewriteRule ^(.*)/$ /show.php?page_url=$1 [L] (removed first slash)

The hard part isn't the code, it's defining precisely what "kinds" or URL-paths you want to rewrite, and what kinds you don't.

Jim

phparion

4:41 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I will not have .php within the slashes so i will go with the second rewrite. one more thing, i was reading your article on rewrite where you matched dog word as ^dog$ without square brackets. how can i do that within a condition of rewrite? for example i want to match all pages but not index.php, the following doesn't work for me

RewriteRule ^(index\.php)$(.+)$

:P

i know that $ will end the rule but not sure how to do that. in fact what i wanted to know is that how do we implement LOGICAL AND in the rules e.g

this AND this too, for OR we can use pipe key.

thanks

jdMorgan

2:27 pm on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the mod_rewrite RewriteCond directive. RewriteConds are logically-ANDed unless you add the [OR] flag to override this default.

Jim