skip to Main Content

I have WordPress pages like

https://example.com/mainpage

https://example.com/mainpage/sub-page1

https://example.com/mainpage/sub-page2

https://example.com/mainpage/sub-page3

I have written a RewriteRule just for mainpage

RewriteRule ^mainpage$ mainpage.php [L,QSA]

also tried

RewriteCond %{REQUEST_URI} !^/mainpage/sub-page1
RewriteRule ^mainpage$ mainpage.php [L,QSA]

and

RewriteCond %{REQUEST_URI} !^/mainpage/.*$
RewriteRule ^mainpage$ mainpage.php [L,QSA]

but all the sub-pages also end up in mainpage.php instead of loading the WordPress pages.
How can I stop subpages loading mainpage.php

Any help would be appreciated.
Thank you

2

Answers


  1. Chosen as BEST ANSWER

    My page was https://example.com/mainpage.

    1. I changed the filename to "main_page.php" instead of mainpage.php
    2. Added the rewiterule RewriteRule ^mainpage$ main_page.php [L,QSA]

    These changes worked for me.


  2. Remove $ from the pattern, and add / and write it like this RewriteRule ^mainpage/ mainpage.php [L,QSA]

    Hopefully, this should ignore sub-pages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search