【问题标题】:making sub director as root by htaccess通过 htaccess 将子目录设置为 root
【发布时间】:2017-12-25 07:14:48
【问题描述】:

我在 .htaccess 的帮助下将我的新模板作为根目录

RewriteEngine on
RewriteCond %{REQUEST_URI} !new/
RewriteRule (.*) /new/$1 [L]

但我有一个问题,所有产品图片都在默认的 public_html 上。我如何访问它,如果我想上传产品图片,那么我会收到此错误

Not Found
The requested URL /new/pimgs/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

请帮助解决这个问题。

【问题讨论】:

  • 所以您想将/new 设为除 pimgs 文件夹之外的根文件夹?
  • 是的,但是在新模板中,图像是从 pimgs 调用的,当新文件夹转换为根目录时,我的新模板无法访问图像。

标签: .htaccess url-rewriting root


【解决方案1】:

您应该进行排除以检查 URI 是否不是以 /pimgs/ 开头的:

RewriteCond %{REQUEST_URI} !^/pimgs/
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1 [L]

第 1 行:测试请求 URI 是否不以 /pimgs/ 开头

第 2 行:测试请求 URI 是否不以 /new/ 开头

第 3 行:如果第 1 行和第 2 行都满足,则将 URL 重写为/new/$1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 2013-05-11
    • 2020-11-25
    • 2016-09-24
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    相关资源
    最近更新 更多