sheegoth — 2012-11-13T15:49:47-05:00 — #1
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.
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.
stevie_d — 2012-11-13T16:13:25-05:00 — #2
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!
sheegoth — 2012-11-13T16:30:38-05:00 — #3
Thank you for the timely reply.
I managed to achieve what I wanted with the following code.
RewriteRule ^(.*).php$ index.php?page=$1 [L,QSA]
Unfortunately however, my attempts at altering the 404 page has proven futile as of late.
dklynn — 2012-11-14T00:52:48-05:00 — #4
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).