rewrite rules – How can i redirect one url to another url using .htaccess or add_rewrite_rule

Question

I am stuck at redirecting one url to another url.

I want to redirect

https://samedomain.com/page-check-927GSJAYS639AL/highlights

to

https://samedomain.com/page-highlights/

(927GSJAYS639AL this is id it can be anything)

the http://samedomain.com/page-highlights/ is the wordpress page

The rewrite rule I tied in .htaccess file (added this in the first line it-self) is:

RewriteEngine On
RewriteRule ^page-check-([A-Z0-9_-]+)/highlights$ page-highlights?id=$1 [L]

but I see a 404 error page

It worked for

RewriteEngine On
RewriteRule ^page-check-([A-Z0-9_-]+)/highlights$ info.php?id=$1 [L]

I also tried WP rewrite API php code

add_action('init', 'ao_add_rewrite_rule');
function ao_add_rewrite_rule() {
   add_rewrite_rule('^page-check-([A-Z0-9_-]+)/highlights$', 'page-highlights?id=$1', 'top');
   flush_rewrite_rules();
 }

No Luck 🙁

Any help is highly appreciated. Thanks in advance.

0
chandana Gowda 3 months 2022-05-06T12:54:27-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse