.htaccess RewriteEngine打破了CSS / Images

I successfully was able to rewrite my dirty urls to clean urls but this broke my image and style folders too :(

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /www/index.php?page=$1&cmd=$2 [L]

That's probably because your styles are going to index.php too now. What I mean is

/styles/myStyle.css -> /www/index.php?page=styles&cmd=myStyle.css

So you should probably fix this by only rewriting some URLs. Like something like this?

RewriteRule ^pages/([^/]*)/([^/]*)$ /www/index.php?page=$1&cmd=$2 [L]

Add the follwing rewrite conditions to prevent rewriting of URLs that lead to existing files and directories, e.g. your JS, CSS and image files.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ /www/index.php?page=$1&cmd=$2 [L]

If your images still don't show up, it's probably because you're including images like this: <img src="./img/myimage.png" />. If you now point your browser to http://site.com/page/hello/, your browser will be looking here for the image: http://site.com/page/hello/img/myimage.png. However, the image is actually here: http://site.com/img/myimage.png.

So you'll have to include your images like this: <img src="/img/myimage.png" /> (everything after the domain). This will force the browser to look ìn the correct place. (Assuming that your directory structure is like this.)