Forum Moderators: phranque

Message Too Old, No Replies

I need a bit of help with a rewrite rule

Simple rewrite rule that I can't pull off

         

catalin

12:11 pm on Apr 3, 2011 (gmt 0)

10+ Year Member



Hello,

I'm trying to put together a fairly simple rewrite rule but for some reason I can't succeed

It should do the following:

domain.com/test_dir/category/order_by/order_by_period/page ->
domain.com/test_dir/page.php?c=category&o=order_by&op=order_by_priod&p=page

where category, order_by, order_by_period are lists of words (eg: funny|news..) and page a number. Each of these may or may not exist

domain.com/test_dir/
domain.com/test_dir/category/
domain.com/test_dir/category/order_by/
domain.com/test_dir/category/order_by/order_by_period
domain.com/test_dir/category/order_by/order_by_period/page

Only condition is order_by_period may be present only if order_by is present

This is what I came up with:

RewriteEngine on
RewriteBase /test_dir
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((categ1|categ2)/)?((order_by1|order_by2)/)?(?<=((order_by1|order_by2)/)(order_by1_period|order_by2_period))?([1-9]?[0-9]*/)? page.php?categ=$2.. [L]


My first problem is .css file doesn't load. I understood why and that the solution to it is to use:
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f

Still didn't work

Hope this is not too hard to follow

Thank you in advance
Catalin

g1smd

12:36 pm on Apr 3, 2011 (gmt 0)

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



The logic of "not this [OR] not that" will ALWAYS evaluate as true.

Think about it.

Delete the [OR]. You need "not this" and "not that".

The URL for the CSS file is evaluated by the browser. If it is a relative link, the browser will be looking for
example.com/test_dir/category/order_by/order_by_period/style.css
or
example.com/test_dir/category/order_by/style.css
. The trick is to start the link to the CSS file with a slash, so it is root-relative:
/styles/style.css
or similar. Do not include the protocol or domain in the link.