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:
(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):
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!
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 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!