htaccess设置请求从管理文件夹索引从基本文件夹子目录加载

时间:2018-09-10 12:36:46

标签: php .htaccess

我想从 bacchus / admin / index.php 调用 bacchus / public / img / logo.png 中的文件,但是由于目录需要我跳回到基本页面。

这里需要注意两点,我编辑了htaccess,将 img / logo.png 的请求更改为 public / img / logo.png 因此它将显示图像而无需添加 public / ,第二件事是如果将此文件 admin / index.php 放在 bacchus 有效。

admin / index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Bacchus</title>
</head>
<body>
<img src="<?php echo 'img/logo.png';?>" alt="" srcset="">
</body>
</html>

.htaccess

#get image, code from public folder
RewriteCond %{REQUEST_URI} (\/(js|img|css)\/.*)
RewriteCond %{REQUEST_FILENAME} !(?=admin)admin
RewriteRule ^((js|img|css)\/.*)$ public/$1

RewriteCond %{REQUEST_FILENAME} (?=admin)admin
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^((js|img|css)\/.*)$ /bacchus/public/$1
#prevent cache storing
RewriteCond %{REQUEST_URI} \.(js|css)
RewriteRule ^/$ - [ENV=AD:true,L]
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" env=AD
Header set Pragma "no-cache" env=AD
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" env=AD 

1 个答案:

答案 0 :(得分:0)

将基本href =“ / bacchus /”添加到index.php