Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NikMac

macrumors member
Original poster
Feb 9, 2008
63
0
Canada
Hello,

I'm currently working on a WordPress website where I am trying to implement a dynamic SGF (Smart Game Format) viewer for displaying Go game files using the MaxiGos library.

My goal: any time a visitor clicks on a link on this website ending in .sgf, it opens a game viewer in-browser that they can use to click through the game file.

Approach: I created this rule in .htaccess so that any .sgf file on the website will be redirected to a custom WordPress template page called sgf-viewer.php, with the .sgf file URL stored as a "?sgf_file" variable. This is the .htaccess file:

Code:
RewriteEngine On
RewriteRule ^(.+\.sgf)$ https://example.com/sgf-viewer/?sgf_file=https://example.com/$1 [R,L]

(of course, I replace example.com with my actual URL to the WordPress root directory).

Here is the code for sgf-viewer.php (which is located in my WordPress theme's directory):

Code:
    <script src="https://example.com/maxigos/maxigos-eidogo-tree.js" data-maxigos-sgf="PLACEHOLDER_SGF_URL"></script>
    <script>
        // Replace the placeholder SGF URL with the actual URL
        var sgfFile = '<?php echo esc_js($_GET['sgf_file']); ?>';
        var scriptTag = document.querySelector('[data-maxigos-sgf="PLACEHOLDER_SGF_URL"]');
        scriptTag.dataset.maxigosSgf = sgfFile;
    </script>
I excluded the PHP template name and header from this example because it appears this forum blocks posts with that content.

I created a page within WordPress with the slug /sgf-viewer and assigned the sgf-viewer.php template to this page.

Problem:
With this configuration, the redirect appears to work, for example https://example.com/endgame.sgf successfully redirects to https://example.com/sgf-viewer/?sgf_file=https://example.com/endgame.sgf. However, the MaxiGos SGF viewer loads a blank game board. There are no errors in the Javascript console.

On the other hand, if I comment out the .htaccess RedirectRule, then https://example.com/sgf-viewer/?sgf_file=https://example.com/endgame.sgf loads the SGF file in the viewer successfully and works as expected.

Summary: I think what is happening here is that with the .htaccess rules enabled, the website is redirecting to the sgf-viewer.php page but then when it tries to load the SGF file URL in the javascript on that page the .htaccess rules are interfering with that process.

I am not sure how to proceed. Does anyone have any creative ideas?

Thanks!
 

NikMac

macrumors member
Original poster
Feb 9, 2008
63
0
Canada
An Update -

I have tried appending a '&skip_redirect=true'; parameter to the sgfFile variable that is fed into the data-maxigos-sgf attribute in the Javascript.

Then I added a !skip_redirect=true condition to the .htaccess RewriteRule.

However it still doesn't work and from some hardcoded tests it appears the MaxiGos SGF Viewer does not work then the data-maxigos-sgf attribute contains any parameters in the URL. I am going to try contacting the MaxiGos developers about this. In the meantime any further suggestions would be much appreciated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.