-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.htaccess
More file actions
40 lines (35 loc) · 2.18 KB
/
Copy path.htaccess
File metadata and controls
40 lines (35 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# =================================================================================
# ZENITH-TIER APACHE REWRITE RULE DECK (.htaccess)
# =================================================================================
# Manages clean URLs, hides server file extensions, and preserves query parameters.
# Supports path-info routes (e.g. /b2_gateway/{id}/{file}).
#
# REDIRECT-LOOP HARDENING:
# • Rule 1 aborts the entire rewrite chain for already-rewritten requests.
# Apache sets REDIRECT_STATUS=200 after an internal rewrite; checking it
# non-empty prevents the rule from firing a second time on the same request.
# • Rule 2 (301 canonicalization) is guarded to only match .php extensions in
# the original browser-sent request (THE_REQUEST), not on internal rewrites.
# • Rule 3 (extensionless → PHP) only fires when the file does not already
# exist on disk AND when REDIRECT_STATUS is empty (first pass only).
# =================================================================================
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# ── Rule 1: Halt all further rewriting once Apache has already rewritten ──
# REDIRECT_STATUS is set to "200" by Apache after the first internal rewrite.
# Without this guard every internal rewrite triggers another full pass, which
# can create 302/301 loops when combined with the canonicalization rule below.
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule ^ - [L]
# ── Rule 2: Canonical SEO redirect — strip .php from browser-visible URLs ──
# Only matches if the RAW browser request (THE_REQUEST) contains ".php".
# Internal rewrites never appear in THE_REQUEST, so this never double-fires.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.\ ]+)\.php([^?\ ]*)
RewriteRule ^([^.]+)\.php(.*)$ /$1$2 [R=301,L,QSA]
# ── Rule 3: Internally route extensionless URLs to their PHP files ──
# Only triggers when the URL does not map to a real file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(index|settings|upload|ads|login|logout|api|stream|b2_gateway)(/.*)?$ $1.php$2 [L,QSA]
</IfModule>