This is my .htaccess
in the root directory that’s supposed to get rid of "public" from URLs:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This is my .htaccess
in the public directory that’s supposed to get rid of trailing slashes:
<IfModule mod_rewrite.c>
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
</IfModule>
This is all well and good, except that when I enter a URL with a trailing slash, it redirect back to a URL with no trailing slash, but also with /public
added.
For example, we have this route:
Route::get('/de', 'HomeController@index')->name('home');
Normally, the URL looks like domain.com/de.
But, if I type in domain.com/de/
into the browser, it redirects to domain.com/public/de
instead of to domain.com/de
– and the page loads as normal.
How do I fix this?
2
Answers
Apache/Nginx should be pointing to the public directory instead of the project root.
This way you don’t need to add any .htaccess rule to get rid of the "public" string in the URLs
Your site root .htaccess should be like this:
Then inside
public/.htaccess
have this code:Make sure to completely clear your browser cache before testing this change.