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.
Options +FollowSymlinks
RewriteEngine on
ErrorDocument 404 404.php
RewriteRule ^(.*).php$ index.php?page=$1
Also, my 404 error doesn’t work; it just displays raw text of “./404.php” instead of redirecting me to the 404 page.
Help would be magnificently appreciated.
[font=verdana]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.
Try putting /404.php for the error document. That seems to work for me![/font]
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).