views:

991

answers:

2

Here is the directory outline:

/
/css
/js
/admin
/config
/etc...

So this is what I would like:

/                      <-- Mod re-write for this directory only, skip the rest
/css
/js
/admin
/config
/etc...

.htaccess file:

# Turn rewrite engine on
RewriteEngine On

# Set the base path
RewriteBase   /

#  now the rewriting rules
RewriteRule ^([0-9A-Za-z]+)/?$ /query.php?id=$1 [L]

Would like to skip all directories except the root directory, how do I do this?

A: 

Have you tried to put a .htaccess file in every sub-directory with "RewriteEngine Off"?

(Maybe this is a question for serverfault.com)

lg
hmm not what I wanted to do but it does solve the problem, thnx
Phill Pafford
+3  A: 

Another solution: Put one of these rules in front of your rules:

RewriteRule ^(css|js|admin|config|…)(/|$) - [L]

RewriteCond %{DOCUMENT_ROOT}$0 -d
RewriteRule ^[^/]+ - [L]

The last named rule will work for any existing directory but only if placed in the .htaccess file in the document root of the server. Otherwise you will need to adjust the RewriteCond expression %{DOCUMENT_ROOT}$0 with the specific path, e.g. %{DOCUMENT_ROOT}foo/bar/$0.

Gumbo
This is exactly what I wanted, thnx
Phill Pafford
One more thing, do I need to add the expression on this as well?Org: RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]Yours: RewriteRule ^(css|js|admin|pages|includes|images)(/|$) - [L]New: RewriteRule ^(css|js|admin|pages|includes|images)(/|$ /yourls-go.php?id=$1) - [L]
Phill Pafford
@Phill Pafford: No, the substitution `-` means *don’t change anything*. The rule is supposed to be the only rule that is applied on that requests and then end the rewriting process while preserving the requested URI.
Gumbo