htaccess – Rewriting subfolders to specific parent folder in WordPress

Question

I have created one page with name /parent/ and assigned new template template-parent.php that has some 3rd party software showing via JavaScript. I need to rewrite all subfolders to this parent so when someone tries to access

domain.com/parent/something

the url will remain the same, but he will be pointed to domain.com/parent/ so that loaded scripts could process the request.

The code should be something like this

RewriteRule ^(parent)/(.+)$ /$1/ [QSA,L]

but I am not sure where to put it, should I use .htaccess or put it in functions.php
If in htaccess, then will it be before, after or in the middle of wordpress code.

in progress 0
emir 2 months 2021-05-24T17:42:26-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-05-30T08:49:54-05:00

    That RewriteRule won’t work regardless where it is placed in the .htaccess file, so you should instead use add_rewrite_rule() – or there is add_rewrite_endpoint(), but if you want to target specific Pages only, then the former function is better.

Leave an answer

Browse
Browse