dousi7919 2016-10-27 04:18
浏览 32
已采纳

我不想从Laravel 5.1的公共目录中提供内容

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条回答 默认 最新

  • dongshi3605 2016-10-28 01:18
    关注

    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:

    # Handle Front Controller...
    RewriteCond $0 =public [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^[^/]* index.php [L]
    

    That should ignore the directory check for just /public/ and leave other functionality unchanged.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部