views:

1293

answers:

2

I need to have a .htaccess rewrite rule redirect to a script in the root of a subdirectory, but only for any files/directories in that sub directory...

/
/subdir/
   /index.php
   /somedir/
   /anotherdir/

For the structure above, I want anyone browsing to /subdir to go to /subdir/index.php, and anyone going to /subdir/somedir/ to /subdir/index.php etc...

If however, they go to the root directory. they should stay there... I've tried putting an .htaccess file in /subdir with a bunch of attempts at rewrite rules but so far none work.

update: I don't mean just the /somedir/ needs to redirect ot index.php, but any subdirectory of /subdir/ needs to be redirect... Scripts too, but obviously not /subdir/index.php

Sorry I wasn't clear before.

A: 

If I'm understanding your question, the only actual redirection that needs to happen is if someone goes to /subdir/somedir (redirect them back to the index.php

If that's the case, this should work, put in /.htaccess:

redirect /subdir/somedir/ /subdir/
ahockley
A: 

If you just want an internal redirect, try this mod_rewrite example:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subdir/somedir/index\.php
RewriteRule ^subdir/somedir/ subdir/index.php [L]

For an external redirect, just add the R flag (with an optional redirect status code: R=xxx; default: 302):

RewriteRule … [L,R=xxx]
Gumbo