[英]URL rewriting in wp fuctions.php without htaccess
是否可以在没有 htaccess 的情况下在 wp fuctions.php 中重写 URL? 我想将下面的代码转换为标准的 wp 重写规则。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteRule ^photo-gallery/surgical/(.*)/(.*)/(.*)/$ wp-content/themes/example-theme/surgical-photo-gallery-details.php?catid=$1&subid=$2&pid=$3```
您可以将此代码块添加到主题的 functions.php 文件中。
add_action( 'init', 'add_author_rules' );
function add_author_rules() {
add_rewrite_rule(
"writer/([^/]+)/?",
"index.php?author_name=$matches[1]",
"top");
add_rewrite_rule(
"writer/([^/]+)/page/?([0-9]{1,})/?",
"index.php?author_name=$matches[1]&paged=$matches[2]",
"top");
add_rewrite_rule(
"writer/([^/]+)/(feed|rdf|rss|rss2|atom)/?",
"index.php?author_name=$matches[1]&feed=$matches[2]",
"top");
add_rewrite_rule(
"writer/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?",
"index.php?author_name=$matches[1]&feed=$matches[2]",
"top");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.