admin 发表于 2025-1-8 16:50:08

【独立版】Apache伪静态规则

# 禁止访问 runtime 和 application 目录
<DirectoryMatch "(runtime|application)">
    Require all denied
</DirectoryMatch>

# 如果请求的文件不存在,重写到 index.php?s=
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?s=/$1
</IfModule>

# H5 子目录处理
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/h5
    RewriteCond %{DOCUMENT_ROOT}/h5%{REQUEST_FILENAME} -f
    RewriteCond %{DOCUMENT_ROOT}/h5%{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ /h5/$1
    RewriteRule ^/h5(/.*)?$ /h5/index.html
</IfModule>

admin 发表于 2025-1-10 11:25:57

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 禁止访问 runtime 和 application 目录
    RewriteRule ^(runtime|application)/ -

    # 伪静态规则,未找到文件时重定向到 index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?s=$1

    # 针对 /h5 的特殊处理
    RewriteCond %{REQUEST_URI} ^/h5
    RewriteCond %{DOCUMENT_ROOT}/h5%{REQUEST_URI} -f
    RewriteCond %{DOCUMENT_ROOT}/h5%{REQUEST_URI} -d
    RewriteRule ^/h5/(.*)$ /h5/$1

    # 未找到文件时返回 index.html
    RewriteCond %{REQUEST_URI} ^/h5
    RewriteRule ^/h5(.*)$ /h5/index.html
</IfModule>

页: [1]
查看完整版本: 【独立版】Apache伪静态规则