This is too tricky for me to figure out ...not sure it can be done. I want my URL structure to look like: http://example.com/foo/ http://example.com/bar/ and call: http://example.com/index.php?page=foo http://example.com/index.php?page=bar That part's easy, but I want one folder (where I store images, JavaScript, CSS, etc) to be ignored. Let's assume it is: http://example.com/lib/ ...and my sub-folders are: http://example.com/lib/img/ http://example.com/lib/css/ etc... Is there a way to do this while ignoring /lib/?
I'm thinking this might work, but I don't have an environment to test it in. Just a live server. Could someone verify? RewriteEngine On RewriteBase / RewriteRule ^lib/$ lib/ RewriteRule ^(.*)/$ index.php?page=$1 [L] Will Apache stop running rules after the first match?
Actually... I remembered I had an unused domain and tested it. My solution was mostly correct. I was just missing an [L] Here's the solution if anyone has the same issue: RewriteEngine On RewriteBase / RewriteRule ^lib/$ lib/ [L] RewriteRule ^(.*)/$ index.php?page=$1 [L]
You need to add "RewriteRule ^lib/(.*)/$ lib/$1/ [L]" to include sub-directories under your library ("lib"). Otherwise, those directories will redirect as well. The code will look like this. RewriteEngine On RewriteBase / RewriteRule ^lib/(.*)/$ lib/$1/ [L] RewriteRule ^lib/$ lib/ [L] RewriteRule ^(.*)/$ index.php?page=$1 [L]