| Server IP : 3.147.158.171 / Your IP : 216.73.216.229 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/builder/backend/scripts/ |
Upload File : |
#!/usr/bin/env python3
"""
Write SPA fallback .htaccess
Generates a single .htaccess file that routes any non-file/non-dir request
to index.html, so Angular SPA client-side routes work when the app is
hosted under a subpath (e.g. wp-content/uploads/tsai/player/browser/).
Usage:
python write_spa_htaccess.py <output_path> <base_href>
Example:
python write_spa_htaccess.py /path/to/dist/scike/wp-shared/player/browser /wp-content/uploads/tsai/player/browser/
"""
import os
import sys
def write_htaccess(output_path: str, base_href: str) -> None:
if not base_href.endswith('/'):
base_href += '/'
lines = [
'RewriteEngine on',
f'RewriteBase {base_href}',
'RewriteCond %{REQUEST_FILENAME} !-f',
'RewriteCond %{REQUEST_FILENAME} !-d',
'RewriteRule ^ index.html [L]',
]
htaccess_path = os.path.join(output_path, '.htaccess')
with open(htaccess_path, 'w') as f:
f.write('\n'.join(lines) + '\n')
print(f"SPA fallback .htaccess written: {htaccess_path}")
def main():
if len(sys.argv) != 3:
print("Usage: python write_spa_htaccess.py <output_path> <base_href>")
sys.exit(1)
output_path = sys.argv[1]
base_href = sys.argv[2]
if not os.path.exists(output_path):
print(f"Error: Directory not found: {output_path}")
sys.exit(1)
write_htaccess(output_path, base_href)
if __name__ == "__main__":
main()