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 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?