【问题标题】:redirect .htaccess file to work for another file in another directory将 .htaccess 文件重定向到另一个目录中的另一个文件
【发布时间】:2018-10-13 19:34:59
【问题描述】:

在我的网站中,我有两个文件 index.php.htaccess。两者都位于目录public_html/image/public 中。 .htaccess 文件的作用我不必在 URL 中提及 index.php。这是.htaccess的代码:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

所以www.example.com/image/public/ 指向index.php。 现在,如果我将index.php 移动到public_html 而不移动.htaccess,我怎样才能再次实现与以前相同的功能(意味着不必在URL 中提及index.php)。我想我必须对.htaccess 文件进行一些更改,但我似乎无法解决。

【问题讨论】:

  • public_html 不是服务器文档根吗? .htaccess 文件应该在 docroot 中,这是一个标准的路由脚本; PHP 中几乎所有可用的 MVC 框架都使用这种类型。
  • 哦-无论如何,您永远不必在 URL 中提及index.php,正常的 Apache 目录索引应该处理该问题-RewriteRule 用于路由 everyindex.php 请求不是现有文件或目录的请求。您可以使用 MVC 框架来执行此操作,因为 index.php 确定相关的控制器和操作。

标签: php apache .htaccess web


【解决方案1】:

用这个更改RewriteRule

RewriteRule . /index.php [L]

但是,如果您只是想在有人点击没有图像名称的图像路径的 URL 时禁用所有图像的列表,则可能是这样的 www.example.com/image/public/

您可以这样做,只需使用以下代码更改 .htaccess 文件的所有内容

Options -Indexes

【讨论】:

  • 您好,感谢您的回复。虽然我得到了一个概述,但如果可以的话,我会要求你详细说明一下,只是为了我更好地理解。提前致谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-23
  • 1970-01-01
  • 2014-02-07
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多