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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?