小编Mar*_*cin的帖子

htaccess阻止访问目录,但允许访问文件

我有这种情况。我正在Zend Framework和htaccess中开发应用程序,将每个请求都指向index.php。如果请求路径上存在某些文件或目录,则htaccess允许访问此文件,例如css,js,图像等。

现在,例如,我有这样的链接:

example.com/profile/martin-slicker-i231

使用Zend Router,它指向控制器帐户和操作视图配置文件。我想为我的用户添加一些avatart,并在公共文件夹中创建目录(这样,服务器和css和js这样的服务器都可以访问图像)。该目录名为“配置文件”,其中的子目录为“ martin-slicker-i231”。服务器可以看到所有路径,如下所示:

public/
  .htaccess
  index.php
  profile/
    martin-slicker-i231/
      avatar-small.jpg
Run Code Online (Sandbox Code Playgroud)

问题是,当我将浏览器指向example.com/profile/martin-slicker-i231时,它将我指向该目录,而不是控制器和操作。当我与用户一起删除文件夹时,流程转到控制器并执行操作。如何配置.htaccess,以便example.com/profile/martin-slicker-i231将指向控制器和操作,但对example.com/profile/martin-slicker-i231/avatar-small.jpg的请求则指向该文件。这是我的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

php directory .htaccess zend-framework apache2

5
推荐指数
1
解决办法
3413
查看次数

htaccess意外重定向到文件夹

我对我的问题很奇怪.我正在开发Zend Framework应用程序并具有以下文件结构:

/
/application/
/public/
/public/.htaccess
/public/index.php
/public/js/
/public/style/
/public/profile/
/.htaccess
Run Code Online (Sandbox Code Playgroud)

我的域名指向 folder /

当我输入地址时,example.com/profile/它会转到控制器配置文件,这很好.当我输入地址时example.com/profile,服务器会将我重定向到: example.com/public/profile/

我希望有一个解决方案,无论何时我要求: example.com/profile/example.com/profile

将呈现相同的页面,但第二个版本给我一个重定向,我不知道为什么.

/.htaccess文件是:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Run Code Online (Sandbox Code Playgroud)

此文件的作用是将所有流量从/向/ public路由,但不进行任何重定向.

/public/.htaccess文件是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我吗?谢谢.


我修好了.如果有人遇到同样的问题,这是解决方案:要解决此问题,您必须设置以下选项并禁用DirectorySlash

Options -Indexes FollowSymLinks
DirectorySlash Off
Run Code Online (Sandbox Code Playgroud)

现在,当你指向目录时,Apache不应该在uri的末尾添加尾部斜杠.这也禁用了使用尾部斜杠重定向到uri.

php apache .htaccess redirect zend-framework

5
推荐指数
1
解决办法
395
查看次数

分组按指定的有序行数

我的MySQL数据库中有这样的表:

---------------------------
|fid | price | date       |
---------------------------
|  1 | 1.23  | 2011-08-11 |
|  1 | 1.43  | 2011-08-12 |
|  1 | 1.54  | 2011-08-13 |
|  1 | 1.29  | 2011-08-14 |
|  1 | 1.60  | 2011-08-15 |
|  1 | 1.80  | 2011-08-16 |
Run Code Online (Sandbox Code Playgroud)

fid- 这是产品ID
price- 这是指定日期内产品的价格

我想计算产品的平均价格fid=1.我想计算n=3按日期排序的第一行的平均价格fid,然后计算按日期排序的另外3行的平均价格.

如何分组前3行并计算平均值,然后将下3行分组并计算平均值.在计算之前,我需要按日期对行进行排序,然后对行进行分组n.

如果n=3这应该返回这样的结果:

--------------
|fid | price |
--------------
|  1 | 1.40 …
Run Code Online (Sandbox Code Playgroud)

mysql group-by sql-order-by limit

5
推荐指数
1
解决办法
98
查看次数