我有一个特殊的情况,需要一些帮助来完成最后一步。
Background:
当我访问mydomain时。com/category/postname,我如期得到了这篇文章。当我访问mydomain时。com/category/postname?ajax=1,我得到了post-html(烘焙到并包括其相应的页面模板标记,这对于这个用例非常重要),但我得到了它的呈现without 它的页眉和页脚(我是故意这样做的,在header.php和footer.php文件中使用$\\u GET[\'ajax]==1条件来抑制它们)。
This all works as expected. 然而,这给我留下了一个新的小问题。。。浏览器无法正确缓存以GET参数字符串结尾的URL中的内容。
Therefore, 我想创建一个重写规则,以实现以下目标。。。
mydomain。com/ajax/category/postnamebecomesmydomain。com/category/postname?ajax=1
Here\'s from my functions.php:
function dynaload_rewrite() {
add_rewrite_rule(\'ajax/(.*)/?\', \'$matches[1]?ajax=1\', \'bottom\');
}
add_action(\'init\', \'dynaload_rewrite\');
This results in .htaccess file as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteRule ^ajax/(.*)/? /$matches[1]?ajax=1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Expected Result: 当我访问ajax/category/postname时,我希望呈现来自/category/postname的内容,减去页眉和页脚,就像我正常使用访问时一样?ajax=1Actual Result: 我收到了WordPress 404页面的内容,但是页眉和页脚are 省略(因此我知道参数ajax=1传递正确,只是加载了错误的页面)。
感谢您的成功帮助,并将被视为令人印象深刻。非常感谢。