I’ve a Larvel 5.1
project running absolutely fine. let’s say it’s hosted at http://www.example.com
. When I go to this address
, it’s working aboslutely fine and there is no public/
in URL which is required. Now the only problem is that if someone goes to http://www.example.com/public/
explcitly, he sees homepage contents without any CSS and JS loaded which is totally not good for SEO as it’ll count as duplicated site. I’ve tried searching over internet but everyone is answering how to remove public/
from URL, but in my case it’s already removed. I just don’t want user to see contents inside public/
if he goes there explicitly. Is there any way to achieve this? I’ll post my .htaccess
file too here. It got many code, for enabling cache, adding www.
with domain. Please help me to resolve this problem. I’m totally stuck.
Here is my .htaccess
file contents
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
# Add a far future Expires header for fonts
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresDefault "access plus 1 week"
</IfModule>
## EXPIRES CACHING ##
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
2
Answers
in root create .htaccess page with the following content.
It stems from what I think is a lazy design decision, allowing all directories and files to be entry points. WordPress does the same thing. You could fix it like so:
That should ignore the directory check for just
/public/
and leave other functionality unchanged.