Just Can't Figure It Out
I want to change "index.php?page=page2" to "page2.php" using .htaccess. How could this be accomplished?
I have tried the following, but to no avail.
Also, my 404 error doesn't work; it just displays raw text of "./404.php" instead of redirecting me to the 404 page.
ErrorDocument 404 404.php
RewriteRule ^(.*).php$ index.php?page=$1
Help would be magnificently appreciated. :)
As I understand it, commands in .htaccess only work on the file name and path, and not on any query parameters. So as far as .htaccess is concerned, you've referenced index.php, not index.php?page=page2, because it ignores the query parameters.
Originally Posted by Sheegoth
Try putting /404.php for the error document. That seems to work for me!
Thank you for the timely reply.
I managed to achieve what I wanted with the following code.
Unfortunately however, my attempts at altering the 404 page has proven futile as of late.
RewriteRule ^(.*).php$ index.php?page=$1 [L,QSA]
First, you've got to get the syntax correct for ErrorDocument to work - and that REQUIRES the redirection to be absolute (internal or external) so all you need is a preceding / or http://example.com/404.php. Of course, it helps if you have a 404.php script in your DocumentRoot.
Finally, why do you not expect (.*)\.php to match your index.php redirection (and loop until it gets tired of looping)? Please have a read about (.*) in my signature's tutorial and why it's so BAD to use nearly all the time (and especially in this case).