简体   繁体   中英

Wordpress htaccess internal redirect not working

I want to run an internal redirect (not changing URL in browser) from /recommendations/xxxx to /recommendations/ (which is the home of an SPA that will handle the routing), but I can't quite land the syntax (the [PT] comes from the apache pages ). Can anyone help?

# 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>

OK, so I don't fully understand where add_rewrite_rule starts and .htaccess ends, but turned out no special htaccess was needed, but I did need:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM