.htaccess删除子目录中的公用文件夹和index.php

时间:2014-11-04 15:26:53

标签: php regex apache .htaccess mod-rewrite

我正在构建一个分配在子文件夹中的API。这个api的第一个版本位于api.com/v1,下一个版本是版本四,位于/ v4。

版本1没有使用任何框架,只是直接的PHP。 api的第4版使用Laravel作为基础。从而产生一个公用文件夹。我不希望API网址像#api.com/v4/public/entry'。

使用提供的.htaccess过滤index.php并使用提供的.htaccess工作正常,但是我没有过滤掉公共文件夹和index.php文件,同时保留了URL中的v4子目录。

我不确定这是否可能。

因此api.com/v4/img/banner.png应链接到api.com/v4/public/img/banner.pngapi.com/v4/gis/layer1.xml应链接到api.com/v4/public/index.php/gis/layer1.xml

到目前为止我的.htaccess文件位于v4文件夹中。 (位于公共文件夹中的.htaccess文件的修改版本,用于从URL中过滤掉' index.php')

RewriteEngine On

# add basic auth support
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}public/index.php [NC,L]

0 个答案:

没有答案