htaccess的异常使问题在主目录 [英] .htaccess exception makes issue on main directory

查看:146
本文介绍了htaccess的异常使问题在主目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的目录结构

localhost or livehost
-app
-bootstrap
-public
-vendor
-code
-demo

下面是我的.htaccess

Here is my .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteRule ^(.*)$ public/$1 [L]
    RewriteRule ^(.*)$ public/blog/$1 [L]
</IfModule>

下面是我的路线

Route::get('/', 'Sys@Home');
Route::get('blog', 'Sys@Blog');
Route::get('contact', 'Sys@Contact');

要访问这些,我并不想进入我的网址为

To access these , I don't want to enter my url as

localhost/public/
localhost/public/blog
localhost/public/contact

相反,它足以进入为

Instead its enough to enter as

localhost
localhost/blog
localhost/contact

与此同时,它不应该适用于这些文件夹 / code /演示访问该目录。

所以我就写例外,从这个问题的.htaccess例外特定的文件夹这些目录

So I got to write exception to these directories from this question .htaccess exception to particular folders

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteRule %{THE_REQUEST} /code
    RewriteRule %{THE_REQUEST} /temp
    RewriteRule ^ - [L]
    RewriteRule ^(.*)$ public/$1 [L]
    RewriteRule ^(.*)$ public/blog/$1 [L]
</IfModule>

在应用此我能够访问该文件夹后本地主机/ code

localhost/demo

但我不能能够访问该文件夹像

But I can't able to access the folder like

localhost
localhost/blog
localhost/contact

如何让它既可以吗?

How can i make it both possible ?

推荐答案

您可以试试:

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteBase /

    RewriteCond %{THE_REQUEST} /(code|tmp) [NC]
    RewriteRule ^ - [L]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

这篇关于htaccess的异常使问题在主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆