Reputation: 22956
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
Upvotes: 1
Views: 2514
Reputation: 22956
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 route contact-us
to index.php?p=2
. Since Apache is adding .php and checking if contact-us.php exists, it is not matching the contact-us
route. So I renamed my file to php-contact-us.php
and kept the route and my URL same. So the redirect works as expected now.
Upvotes: 2