Wordpress htaccess内部重定向无法正常工作

时间:2015-07-04 15:25:30

标签: wordpress apache .htaccess

我想在/ recommendations / xxxx中运行内部重定向(不是在浏览器中更改URL)到/ recommendations /(这是处理路由的SPA的主页),但我无法完全解决语法问题([PT]来自apache pages)。有人可以帮忙吗?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /af2015/web/
# RewriteRule ^recommendations/(\w+) /recommendations [QSA,L] # add_rewrite_rule default
# RewriteRule ^recommendations/(\w)$ recommendations/ [PT] # original
RewriteRule ^recommendations/(\w+)$ recommendations/ [PT]   # per Abel's comment 
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /af2015/web/index.php [L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

好的,所以我不完全了解add_rewrite_rule的开始和.htaccess的结束,但结果并不需要特殊的htaccess,但我确实需要:

function recommendations_rewrite() {
  add_rewrite_rule('recommendations/(\w+)', 'index.php?pagename=recommendations', 'top');
}
add_action('init', 'recommendations_rewrite');