Reputation: 23
I have two folders:
/forum/admin
/forum/adminhide
I would like to have a .htaccess file in the forum folder which would internally rewrite everything except index.php on /admin to /adminhide.
Example:
http://website.com/forum/admin/index.php -> don't do anything
http://website.com/forum/admin/image.png -> internal rewrite to http://website.com/forum/adminhide/image.png
All my attempts so far have only produced Server Internal Errors.
Upvotes: 1
Views: 175
Reputation: 50338
This might work (in a root-level .htaccess file):
RewriteRule ^forum/admin/index\.php$ - [S=1]
RewriteRule ^forum/admin/(.*) forum/adminhide/$1
Any URLs matching the first rule will not be rewritten (since the substitution has the magic value -
), and the [S=1]
flag causes the next rule (which does the actual rewrite) to be skipped if the first rule matches.
Note that this interprets your requirements very literally: every URL path beginning with forum/admin/
is rewritten, except for forum/admin/index.php
. You may prefer to change the first rule to something a bit looser, such as:
RewriteRule ^forum/admin/(index\.php(/.*)?)?$ - [S=1]
This will also match (and thus exclude from the rewrite) the URL paths forum/admin/
and forum/admin/index.php/whatever
.
Edit: If you want to put the .htaccess file for this in the forum
folder, just remove the initial forum/
from the rules and set RewriteBase
appropriately instead:
RewriteBase /forum/
RewriteRule ^admin/index\.php$ - [S=1]
RewriteRule ^admin/(.*) adminhide/$1
Upvotes: 1