I'm using the following code, but it's displaying incorrectly.
Error: There is currently an extra "/" in front of the domain name and "[QSA,L]" after the domain name. Hoping someone can help me now.
add_action( 'init', 'mdv_add_rule' );
function mdv_add_rule() {
add_rewrite_rule( 'demo/(. )$', 'https://example.com/$1 [R=301,L]' );
}
Thank you for watching
CodePudding user response:
I need to do it this way in the main htaccess section to avoid the case when using the "options-permalink" setting they will be removed.
To avoid the directives being removed/overwritten when resetting permalinks in WordPress you simply add the directives at the top of the .htaccess
file, before the # BEGIN WordPress
section.
Any external redirect should go before any of the WordPress rewrites anyway (including before that RewriteRule ^index\.php$ - [L]
directive).
You do not need to repeat the RewriteEngine On
directive, since that is already included in the WordPress section that occurs later in the file. (If you have multiple RewriteEngine
directives then the last instance wins and controls the entire file.)