Search code examples
phpapache.htaccesswgetphpbb

How to make viewforum.php?foo=bar request serve a file instead of a PHP code?


I'm archiving a phpBB forum into flat HTML files, without any PHP code anymore. I used wget (see How to: Archive a phpBB forum using Wget and preserve styling), and I now have these files:

enter image description here

How to make Apache serve example.com/forum/viewforum.php?f=2&start=25 as a file, and not as a request to viewforum.php with a query string? The latter does not work obviously and gives a 404.

I already tried this htaccess with no success:

RemoveHandler .php .phtml .php3
RemoveType .php .phtml .php3
php_flag engine off

Note: this is how I archived the forum:

wget -m -p -np -R "*sid=*,ucp.php*,memberlist.php*,*mode=viewprofile*,*view=print*,viewonline.php*,search.php*,posting.php*" https://forums.example.com

Solution

  • Interesting problem indeed! force me to dig many Apache docs. In the end solution was simple i.e. to escape ? so that Apache doesn't treat ? and part after that as query string.

    You may use this rewrite rule in your site root .htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} ^/forum/viewforum\.php$ [NC]
    RewriteCond %{QUERY_STRING} .
    RewriteRule ^ %{REQUEST_URI}\%3F%{QUERY_STRING} [L,NC]
    

    PS: \%3F is escaped ? so make Apache load /forum/viewforum.php?f=2&start=25 as a file.