Options -Indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
RewriteEngine On

# Always serve as https://shariahexplorer.com (skipped when testing on localhost).
# Needs an SSL certificate on the domain first (cPanel: SSL/TLS Status → Run AutoSSL).
# The hosting also exposes this folder as syazmedia.com/shariahexplorer.com/, as
# shariahexplorer.com.syazmedia.com and as www.; all of these go to the one real address.
# $1 is the path relative to this folder, so the extra folder name is dropped.
# If the domain ever changes, update it here and in config.php.
RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:\d+)?$ [NC]
RewriteCond %{HTTP_HOST} !^shariahexplorer\.com$ [NC]
RewriteRule ^(.*)$ https://shariahexplorer.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:\d+)?$ [NC]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^(.*)$ https://shariahexplorer.com/$1 [L,R=301]

# Stock pages: /stock/5398-gamuda  ->  stock.php?code=5398
RewriteRule ^stock/([0-9]{4,5}[A-Za-z]{0,2})(?:-[a-z0-9-]*)?/?$ stock.php?code=$1 [L,QSA,NC]

# Clean page addresses
RewriteRule ^browse/?$ browse.php [L,QSA]
RewriteRule ^changes/?$ changes.php [L,QSA]
RewriteRule ^about/?$ about.php [L,QSA]
RewriteRule ^disclaimer/?$ disclaimer.php [L,QSA]
RewriteRule ^search/?$ search.php [L,QSA]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^api/search-index/?$ api/search-index.php [L]

# Never serve these over the web
RewriteRule ^(storage|inc)(/|$) - [F,L]
RewriteRule ^config\.php$ - [F,L]
</IfModule>

ErrorDocument 404 /404.php

<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set X-Frame-Options "SAMEORIGIN"
</IfModule>

# Compress pages and data (the browse page shrinks from ~306 KB to ~30 KB)
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json application/xml image/svg+xml
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
</IfModule>
