views:

198

answers:

2

Hiya,

I'm trying to rewrite a url of this: http://www.foo.com/bar/baz

to

index.php?q=$1&d=baz

Where bar is not a fixed value, but baz is.

  RewriteRule ^(.*)\/baz$ index.php?q=$1&d=baz [L,QSA]
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

What i have above kinda works but unfortunately breaks all the includes in the site (css/javascript) but strangely all the pages work :/

This is a drupal install, (so the second line needs to remain).

UPDATE

This might help actually, i forgot to include

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  **RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]**
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

It seems to be doing my rewrite correctly, the only problem is it's ignoring the other conditional statements now, i.e. it's still attempting to rewrite files that exist (i.e. css,js) when it's mean to avoid them.

site is fine without my line (The one with the stars), but with it, the variables and pages work, but static files like css etc are also being rewritten....need to stop that!

Thanks in advance.

Shadi

+1  A: 

Conditions only apply to the first rule immediately following. So try duplicating the condition lines.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
David Zaslavsky
Almost, you posted this as i had repositioned the rule, seems it was just conflicting due to the order, but placing my rule above worked without the conditional elements. Thanks for your help anyway! :)
Shadi Almosri
A: 
  RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This is what finally worked. it just required the rearranging of the rules...

Shadi Almosri