CROSP
CROSP

Reputation: 4617

How to redirect all request to subfolder with it's own .htaccess file

I know such questions has been answered a lot of time, but neither of found answers works for me.
I have following url http://dummy.com/api to access my root folder where I am going to have my project (Laravel project).
I am deploying to the remote hosting so I have no acceess to the parent directories.
My project (simple Laravel project) consists from a lot of folders, which by the way should be placed in parent directories (app,bootstrap,config...) and public folder where main index.php of Laravel project is located.
So I have url like this http://dummy.com/api/public/index.php This directory includes it own .htaccess file with following content.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L

This stuff is required by the laravel.

So I need all requests to the http://dummy.com/api have been redirected to the public/ subfolder(index.php by default).
For example http://dummy.com/api/users should be really http://dummy.com/api/pulbic/users.
But this should be transparent for the user and not changed to the real url.
I have tried a lot of different configurations also from here Common .htaccess Redirects

But this doesn't work for me. Please help to create such rules to have desired result.
Thanks everyone in advance.

Upvotes: 1

Views: 2879

Answers (1)

anubhava
anubhava

Reputation: 785128

Try this .htaccess in /api/ folder:

RewriteEngine On
RewriteBase /api/

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

Upvotes: 1

Related Questions