我正在尝试摆脱WP文件夹,并重写自定义PDF的URL,创建了一个基于产品ID的文档。我使用了下面的代码,但它不起作用。
初始值:http://example.com/wp-content/themes/exampletheme/templates/pdf-generator.php?productID=11
我试图获得的价值:http://example.com/carPDF=11
CODE:
add_action(\'init\', \'custom_rewrite_basic\');
function custom_rewrite_basic() {
add_rewrite_rule(\'carPDF=([0-9]+)/?$\', \'wp-content/themes/exampletheme/templates/pdf-generator.php?productID=$matches[1]\', \'top\');
}
我本来可以了解自己,但现在我变得像permalink一样
http://example.com/carPDF/?productID=61
我想删除get参数,而不是只有这样的数字
http://example.com/carPDF/61
CODE UPDATED: 功能。php
add_action(\'init\', \'custom_rewrite_pdfURL\');
function custom_rewrite_pdfURL() {
add_rewrite_rule(\'^carPDF/([^/]*)/?\', \'wp-content/themes/exampletheme/templates/pdf-generator.php?productID=$matches[1]\', \'top\');
}
F
orm。php<form method="GET" action="http://example.com/carPDF/" id="hidden-pdf-form">
<input type="hidden" value="<?php echo "$id"; ?>" name="productID">
<i class="glyphicon glyphicon-download"></i>
<input type="submit" value="Download PDF" class="btn btn-link"/>
</form>
最合适的回答,由SO网友:Worduoso 整理而成
$matches[1]
不适用于外部重定向,仅适用于内部重定向(URL必须以index.php开头,并由WordPress本身处理)
试试这个
add_action(\'init\', \'custom_rewrite_pdfURL\');
function custom_rewrite_pdfURL() {
add_rewrite_rule(\'^carPDF/([^/]*)/?\', \'wp-content/themes/exampletheme/templates/pdf-generator.php?productID=$1\', \'top\');
}
别忘了冲洗permalinks