views:

53

answers:

2

I want to have a url like this: domain.com/css/site.css?test=234

Rule:

RewriteEngine On
RewriteRule ^([a-z]+)/$ $1.php
RewriteRule ^css/([a-zA-Z0-9]+).css?count=(.*)$ css.php?f=$1&test=$2

But I get every time a 404: Not found (site.css)

If I have a rule like that it works, just without getting the $_GET-Variable:

RewriteEngine On
RewriteRule ^([a-z]+)/$ $1.php
RewriteRule ^css/([a-zA-Z0-9]+).css$ css.php?f=$1
A: 

It could be because your files are arranged as follows:

www.mysite.com/script.php
www.mysite.com/css.php

And because of re-writing you are showing this page:

www.mysite.com/script/

And your script.php contains:

<link href="css/site.css?count=1">

Which instructs the browser to fetch:

www.mysite.com/script/css/site.css

And that file does not exist + this resulting url is not defined in your configuration. As a work around, try adding a leading / to the css file path.

Salman A
+2  A: 

Query string is not present in url to be matched by RewriteRule. You need something like this:

RewriteEngine On
RewriteRule ^([a-z]+)/$ $1.php

RewriteCond %{QUERY_STRING} count=(.*)$
RewriteRule ^css/([a-zA-Z0-9]+).css$ css.php?f=$1&test=%1

You can read more about RewriteCond and RewriteRule here http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond

You can see order in which RewriteConds and RewriteRules are executed here http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#InternalRuleset

Kamil Szot
Again learned something new, thanks :)
Poru