dousi7919 2016-10-27 12: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 09: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条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分