I moved my site from local to the server and the rewrite rules in my .htaccess were not working.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^contact-us$ index.php?p=2
</IfModule>
That is what I have in my .htaccess.
But I am sure .htaccess is recognized by the server ( I tested by putting some garbage in .htaccess – I got server error).
To further diagnose the problem, I modified my .htaccess like below:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^contact-us$ index.php?p=2
RewriteRule contact-us$ index.php?p=2
RewriteRule ^contact-us index.php?p=2
RewriteRule contact-us index.php?p=2
</IfModule>
Now, I am getting a strange error while visiting my site.com/contact-us
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'redirect:/index.php' (include_path='.:/usr/lib64/php:/usr/lib/php') in Unknown on line 0
Apache is somehow adding .php to my URL automatically. ( I think because of the AddHandler)
I have a
contact-us.php, but I want to routecontact-ustoindex.php?p=2. Since Apache is adding .php and checking if contact-us.php exists, it is not matching thecontact-usroute. So I renamed my file tophp-contact-us.phpand kept the route and my URL same. So the redirect works as expected now.