0

I am struggeling with something I am trying to do regarding folder. I have a sub-folder called "admin" so I can access the site as mydomain.com/admin.

However I want that if I say mydomain.com/foobar or mydomain.com/28y282djdhjd, then it should always assume it is "admin".

Of course the rule shoud not apply to existing files and folders but it is specifically to the first folder from the domain root.

It's as if I want the admin to be accessed no matter what I call it (as long as it is not a physical folder or file)...

I am not good with htaccess if someone could guide me I would truly appreciate it.

Thank you in advance.

Mihai Pop
  • 65
  • 6

1 Answers1

0

So, you need to:

  1. Check that the request isn't for a file that already exists;
  2. Check that the request isn't for a directory that already exists;
  3. Only redirect the request, if it refers to the first folder-level from the domain root;

If that's all correct, something like this should do it:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\/]*)\/?$ http://example.com/admin [L]
Rounin
  • 27,134
  • 9
  • 83
  • 108
  • I (genuinely) love it that you came back and accepted this answer over four and a half years later. Thank you!! :-D – Rounin Aug 06 '21 at 15:40