So my rewriterule is like
RewriteRule ^test$ index.php [L]
I tested it on https://htaccess.madewithlove.com?share=b0a9904b-1ec4-49cd-917c-36426ff6150a it works fine.
I also tested it on live Joomla sites and on a HTML sites, it all work fine.
However, when I try to test this on a Wordpress site, I am always getting a 404 page. By default, wordpress site's .htaccess file is like
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I add my rewrite rule above to the first line, but when I open mysite.com/test I will get a 404 error.
To test, I create a 1.php
file and modify my rule to
RewriteRule ^test$ 1.php [L]
This time, when I open mysite.com/test it successfully executes 1.php
. So the catch here is index.php
.
What I don't understand is if I open mysite.com/index.php it will load mysite.com without problem. And I believe
RewriteRule ^test$ index.php [L]
in essential is telling the server when user request mysite.com/test show him mysite.com/index.php, then why in actuality I am getting a 404 page(not a blank 404, but the 404 page handled by wordpress's theme) when trying to open mysite.com/test?
P.S. I've also tried removing the default wordpress rules, but still getting the same result.