Score:0

redirect request to folder except for specific request

cn flag

I have this htaccess that redirects all requests to a folder (public folder for laravel framework) and now I have a staging app that is clone from the main application e.g. mydomain.com/staging and I wanted to access the staging folder to run the staging application but it returns me 404

DirectoryIndex index.php

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

and below is the htaccess of /public folder

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Any help, suggestions, recommendations is greatly appreciated, thanks in advance.

kz flag
Presumably you have another `.htaccess` file in the `/staging` subdirectory? What does this `.htaccess` file contain? What is generating the 404? Apache? The "main application"? Or, the "staging" application?
Juliver Galleto avatar
cn flag
@MrWhite yes, I have htaccess also on /staging and its the same htaccess on the above, pointing to public folder of laravel framework
kz flag
And "What is generating the 404?". Providing you have the appropriate `.htaccess` file in the `/staging` subdirectory then you shouldn't have to do anything in this regard - you do not need to add an "exception". You must also have additional `.htaccess` files in the `public` subdirectories - presumably these don't have a hardcoded URL-path? However, your URLs now obviously contain `/staging` - so this will need to be accounted for in your routing (in your application).
Juliver Galleto avatar
cn flag
@MrWhite it simply returning 404 not found due to all request being forwarded to /public folder so if you access /staging folder, it will be forwarded to /public folder that has htaccess also. Kindly see my updated post for the additional htaccess on /public folder
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.