【问题标题】:Wordpress - How to allow direct links to files in subfoldersWordpress - 如何允许直接链接到子文件夹中的文件
【发布时间】:2018-04-09 22:00:17
【问题描述】:

我在站点根目录安装了 wordpress。

www.site.com

如果我将例如 mp3 上传到`

www.site.com/music/123.mp3`

我无法直接链接到要下载的 mp3。

如何启用指向某个子文件夹的直接链接?

我只需要修改 .htaccess 文件吗?是否有插件或特定文件夹允许这样做?

如果我的 wordpress 安装了它就可以正常工作`

www.site.com/blog`

谢谢

【问题讨论】:

  • 在我的 WordPress 测试平台中,我可以正常访问 localhost/music/123.mp3,即使打开了永久链接。你的永久链接设置是什么?也许分享你的.htaccess。您的 /music 目录中有 .htaccess 吗?

标签: wordpress .htaccess


【解决方案1】:

在你的主题或插件中的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 管理员 -> 设置 -> 永久链接,然后单击保存更改(这将刷新您的重写规则)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2014-08-13
    • 2017-01-11
    • 2015-09-10
    • 2014-01-31
    • 1970-01-01
    相关资源
    最近更新 更多