3

I have a directory structure

mymvc
    |--App
    |--Core
    |--logs
    |--public
             |--index.php
    |--vendor
    |--.htaccess

what i want is that if someone hit my url www.example.com/mymvc/ then all the request must go through public->index.php using .htaccess file. i do not have access to httpd.conf file.

|--public
        |--index.php

I want my public folder to be accessible only as a document root and request pass through index.php file inside public folder. No one can access directly App , Core , logs etc. directories. Means i want my public folder to be DOCUMENT ROOT.

1 Answer 1

5

First you need to create an .htaccess file in the root of the project.

mymvc/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]

Then, in the .htaccess file in the public directory (which would be mymvc/public/.htaccess), you need to add a RewriteBase directive to the existing code, so it looks like this:

mymvc/public/.htaccess

# Remove the question mark from the request but maintain the query string
RewriteEngine On
RewriteBase /mymvc
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

1 Comment

Could you explain the details of why are needed two files?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.