.htaccess serving subfolder at from url of another subfolder

49 Views Asked by At

My folder structure looks like this:

    /.htaccess
    /admin
    /admin/api
    /admin/admin
    index.html (Angular JS app)

So I need to do the following rewrites:

  1. Serve /admin/admin at /admin
  2. Serve /admin/api/* at /admin/api/* (no rewrite)
  3. Serve /{everything else} from index.html

How can I do this in the root .htaccess?

So far, I've got:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]
</IfModule>

But this doesn't handle the rewriting of /admin/admin to /admin. Can anyone help with this?

1

There are 1 best solutions below

0
On

You can use:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^admin/?$ admin/admin [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(index|admin)
    RewriteRule ^ index.html [L]
</IfModule>

This is assuming there is no .htaccess inside /admin/ folder. In case there is then use this rule there:

RewriteEngine On
RewriteBase /admin/

RewriteRule ^/?$ admin [L]