Requirement
我已实施Document Short URL
允许用户使用其唯一ID访问服务器上的PDF文档,而不知道其完整路径。文档是PDF文件,所以应该在浏览器中打开它们。这是可行的,所以这不是问题所在。
For example
http://www.example.com/INV0001-00-001
其中INV0001-00-001是Unique ID
My Attempt
add_action(\'init\', \'pins_add_rewrite_rule\', 11);
add_action(\'template_redirect\', \'pins_short_url_redirect\');
function pins_add_rewrite_rule() {
add_rewrite_rule(\'^document/(.*)$\', \'index.php/?action=short_url&id=$1\', \'top\'); // works
add_rewrite_rule(\'^document/(.*)$\', \'index.php?action=short_url&id=$1\', \'top\'); // doesn\'t work
flush_rewrite_rules();
global $wp;
$wp->add_query_var(\'action\');
$wp->add_query_var(\'id\');
}
function pins_short_url_redirect() {
global $wp_query;
if (empty($wp_query->query_vars[\'action\'])) {
return;
}
$action = $wp_query->query_vars[\'action\'];
if ($action == \'short_url\') {
require_once \'classes/class-short-url.php\';
if(class_exists(\'PINS_Short_Document_URL\')){
PINS_Short_Document_URL::init(); // class responsible for pulling the ID and serve the pdf document in browser
// We are done
die();
}
}
}
My Questions
<我做得对吗?还有更好的建议吗add_rewrite_rule 工作,而不是其他?如果在索引后删除“/”。php它不工作。为什么