.htaccess 在wp functions.php中重写URL而不使用htaccess

y3bcpkx1  于 2022-11-16  发布在  PHP
关注(0)|答案(1)|浏览(111)

在没有htaccess的情况下,是否可以在wp functions.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```
u3r8eeie

u3r8eeie1#

您可以将此代码块添加到主题的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");
}

相关问题