1

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?

teabot
  • 15,358
  • 11
  • 64
  • 79
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383

2 Answers2

5

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
  • 643,351
  • 109
  • 780
  • 844
  • This is exactly what I wanted, thnx – Phill Pafford Aug 25 '09 at 16:40
  • 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 Aug 25 '09 at 16:43
  • @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 Aug 25 '09 at 17:14
0

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

(Maybe this is a question for serverfault.com)

lg.
  • 397
  • 2
  • 12