【问题标题】:Load folder on specific Wordpress URL(category URL) with .htaccess使用 .htaccess 在特定的 Wordpress URL(类别 URL)上加载文件夹
【发布时间】:2015-05-30 00:22:11
【问题描述】:

我正在尝试从 Wordpress 中特定(已使用的 URL)上的特定文件夹加载内容(index.html)。

这是 .htaccess 文件(默认):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

我已经尝试过这个重写规则的几个变体:

RewriteRule ^/category/funny-posts/ /funny-images/ [L]

所以 funny-images 是我服务器上安装 WP 的目录。它们都在根文件夹中。

当我输入 www.site.com/category/funny-posts/ 时,如何从 /funny-images/ 加载 index.html?

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite


    【解决方案1】:

    如果index.html 文件未显示(并且您想要的 URI 正在传递给 WP),这可能是因为您将规则放在最后。试着把它放在RewriteEngine On 之后。哦,我认为您不需要RewriteBase。此外,您不需要新规则中的前导斜杠,就在 category 之前。

    您的文件现在应该如下所示:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^category/funny-posts/ /funny-images/ [L]
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    【讨论】:

    • 这确实有效! :) 我现在唯一需要做的就是修复相对路径,因为在 index.html 而不是获取 /js/example.js 它试图获取 /funny-posts/js/example.js
    • 很高兴。您只需要在对 JS 文件的引用中使用前导斜杠。或者,使用 HTML &lt;base&gt; 标签。
    猜你喜欢
    • 1970-01-01
    • 2018-05-15
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2014-04-13
    • 2015-03-28
    相关资源
    最近更新 更多