我在网站的根目录下安装了wordpress。
www.site.com
如果我上传一个mp3到`
www.site.com/music/123.mp3`
我无法直接链接到mp3下载。
如何启用指向某个子文件夹的直接链接?
我只需要修改.htaccess文件吗?是否有允许此插件或某个文件夹?
如果我的wordpress安装了`
,它可以正常工作www.site.com/blog`
由于
答案 0 :(得分:0)
在主题或插件中的functions.php文件中尝试此操作。
function my_custom_htaccess( $rules ){
// Create our condition.
$exclude_cond = PHP_EOL . 'RewriteCond %{REQUEST_URI} !^/(music/.*)$';
// Look for a place to insert it.
// We are going to put this just after the RewriteBase line.
// This is not in the same place as all the other RewriteCond statements,
// But it seems to work.
$search = '/RewriteBase.+/';
// Replace w/ found string, plus condition
$replace = '$0' . $exclude_cond;
// Rock and roll.
$rules = preg_replace($search, $replace, $rules);
return $rules;
}
add_filter('mod_rewrite_rules', 'my_custom_htaccess');
将其添加到某处后,转到您的WordPress管理员 - >设置 - >永久链接,只需单击保存更改(这将刷新您的重写规则)。