views:

77

answers:

4

Hi all SO users!

I'm writing a CMS in PHP, and now I'm working at the themes feature. I have a .htaccess file:

RewriteEngine ON
RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)$ index.php?m=$1
RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)/(.+)$ index.php?m=$1&p=$2

If I have a request to:

/page

it must load the view function of the class called page.

If I have a request to:

/page/test

it must load the view function of the class called page, with the parameter 'test'. This all works,

But I want it to apply the RewriteRules ONLY if the request does NOT start with:

/THEMES/

So I can apply CSS styles etc...

Can anyone help me? Thanks.

+3  A: 

You could use an additional rule to stop the rewriting process:

RewriteRule ^THEMES/ - [L]
RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)$ index.php?m=$1
RewriteRule ^([a-zA-Z][a-zA-Z0-9]*)/(.+)$ index.php?m=$1&p=$2
Gumbo
Good to know you can rewrite to - to preserve a given URL/pattern
eyelidlessness
Thanks man. This worked.
Time Machine
+1  A: 

Add this before your rewrite rules:

RewriteCond %{REQUEST_URI} !^/THEMES/
Kevin
A: 

If you want to include css/js files while using url-rewriting use that tag to specify the main url.

< base href="http://www.your-web-site-adress.com" >

Then you may easily include your css/js files like that:

< script src="/blabla.js" >

it'll add base href as prefix.

Ahmet Kakıcı
A: 

Do something like:

RewriteRule ^THEMES - [L]

That means: if the request starts with THEMES, just serve it.

Another possible solution is:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

That means: do not rewrite if the request resolves to an existing file (first line) or directory (second line).

Maybe you should read the documentations, is really well written.

sydarex
The second one did not work.
Time Machine
Are you sure that the file/directory requested exists? It seems strange to me, it works on my system.
sydarex