Reputation: 89
I tried to search and use the solutions already posted but nothing worked for now and I tried pretty much everything I could but didn't work.
These are the app directories:
localhost/
root/
data/
app/
public/
index.php
.htaccess
The htaccess is this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /root/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
The first problem is that if I go to localhost/root/public the website works as intended but in the url I still see 'public' which I'd like to remove.
The second problem is that my objective is to go to the index from the url localhost/root/ but now, if I go there it just shows the files in the folder.
Thank you.
As requested, these are the routes that I use:
$app->get('/', function () use ($app) {
// code
})->bind('home');
$app->get('/about-me', function () use ($app) {
// code
})->bind('about-me');
Upvotes: 2
Views: 337
Reputation: 406
There are two mistakes in your system.
First: The .htaccess located in the root folder should be used to remove the 'public' part of the URL. The code for that is like the following:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
It basically grabs every route and redirects it to the public folder, exactly as you wished!
Second: You should create another .htaccess file in your '/public' folder to redirect everything to the index.php file. The code for that should look like this:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
You should end up with the following structure:
localhost/
root/
.htaccess (removes 'public')
data/
app/
public/
index.php
.htaccess (forward to index.php)
This should solve both your problems. If it does, please mark the question as completed by marking my answer as the one that solved it. If it does not, please comment on other problems that occur to you!
Upvotes: 1