-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.htaccess
More file actions
163 lines (137 loc) · 5.9 KB
/
Copy path.htaccess
File metadata and controls
163 lines (137 loc) · 5.9 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 禁止访问隐藏文件
RewriteRule ^\.git - [F,L]
RewriteRule ^\.env - [F,L]
# 禁止访问敏感目录
RewriteRule ^config/ - [F,L]
RewriteRule ^storage/ - [F,L]
RewriteRule ^vendor/ - [F,L]
RewriteRule ^includes/ - [F,L]
RewriteRule ^install/sql/ - [F,L]
# 禁止访问敏感文件
RewriteRule ^composer\.(json|lock)$ - [F,L]
# Sitemap
RewriteRule ^sitemap\.xml$ /sitemap.php [L]
# 伪静态规则
# 新闻文章系统
# /news.html -> /news.php
# /news/page/2.html -> /news.php?page=2
# /news/company-news.html -> /news.php?cat=company-news
# /news/company-news/page/2.html -> /news.php?cat=company-news&page=2
# /news/article/1.html -> /article.php?id=1
RewriteRule ^news\.html$ /news.php [L,QSA]
RewriteRule ^news/page/(\d+)\.html$ /news.php?page=$1 [L,QSA]
RewriteRule ^news/article/(\d+)\.html$ /article.php?id=$1 [L,QSA]
# /news/article/my-slug.html -> /article.php?slug=my-slug
RewriteRule ^news/article/([a-z0-9_-]+)\.html$ /article.php?slug=$1 [L,QSA]
RewriteRule ^news/([a-z0-9_-]+)/page/(\d+)\.html$ /news.php?cat=$1&page=$2 [L,QSA]
RewriteRule ^news/([a-z0-9_-]+)\.html$ /news.php?cat=$1 [L,QSA]
# 栏目列表页 (支持ID和slug)
# /list/1.html -> /list.php?id=1
# /list/1/page/2.html -> /list.php?id=1&page=2
# /news.html -> /list.php?slug=news
# /news/page/2.html -> /list.php?slug=news&page=2
RewriteRule ^list/(\d+)\.html$ /list.php?id=$1 [L,QSA]
RewriteRule ^list/(\d+)/page/(\d+)\.html$ /list.php?id=$1&page=$2 [L,QSA]
RewriteRule ^([a-z0-9_-]+)/page/(\d+)\.html$ /list.php?slug=$1&page=$2 [L,QSA]
# 案例详情页
# /case/1.html -> /detail.php?id=1
# /case/my-slug.html -> /detail.php?slug=my-slug
RewriteRule ^case/(\d+)\.html$ /detail.php?id=$1 [L,QSA]
RewriteRule ^case/([a-z0-9_-]+)\.html$ /detail.php?slug=$1 [L,QSA]
# 招聘详情页
# /job/1.html -> /job_detail.php?id=1
RewriteRule ^job/(\d+)\.html$ /job_detail.php?id=$1 [L,QSA]
# 下载详情页
# /download/detail/1.html -> /detail.php?id=1
RewriteRule ^download/detail/(\d+)\.html$ /detail.php?id=$1 [L,QSA]
# 详情页 (支持ID格式)
# /detail/1.html -> /detail.php?id=1
RewriteRule ^detail/(\d+)\.html$ /detail.php?id=$1 [L,QSA]
# 产品详情页 (数字ID优先匹配)
# /product/1.html -> /product.php?id=1
RewriteRule ^product/(\d+)\.html$ /product.php?id=$1 [L,QSA]
# 产品详情页 (分类slug + 产品slug)
# /product/smart-device/iot-gateway.html -> /product.php?slug=iot-gateway
RewriteRule ^product/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ /product.php?slug=$2 [L,QSA]
# 产品分类页 (带分页)
# /product/category-slug/page/2.html -> /list.php?slug=product&cat=category-slug&page=2
RewriteRule ^product/([a-z0-9_-]+)/page/(\d+)\.html$ /list.php?slug=product&cat=$1&page=$2 [L,QSA]
# 产品分类页
# /product/category-slug.html -> /list.php?slug=product&cat=category-slug
RewriteRule ^product/([a-z0-9_-]+)\.html$ /list.php?slug=product&cat=$1 [L,QSA]
# 特殊页面(独立PHP文件,优先于通用规则)
# /company/history.html or /about/history.html -> /history.php
RewriteRule ^(company|about)/history\.html$ /history.php [L]
# /contact.html -> /contact.php
RewriteRule ^contact\.html$ /contact.php [L]
# 单页 (支持多级slug)
# /page/1.html -> /page.php?id=1
# /about.html -> /page.php?slug=about
# /about/company.html -> /page.php?slug=company (子页面)
RewriteRule ^page/(\d+)\.html$ /page.php?id=$1 [L,QSA]
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ /page.php?parent=$1&slug=$2 [L,QSA]
RewriteRule ^([a-z0-9_-]+)\.html$ /page.php?slug=$1 [L,QSA]
# 如果请求的文件或目录不存在
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# 禁止目录浏览
Options -Indexes
# 设置默认文档
DirectoryIndex index.php index.html
# 设置PHP配置
<IfModule mod_php.c>
php_value upload_max_filesize 20M
php_value post_max_size 25M
php_value max_execution_time 300
</IfModule>
# 缓存静态文件
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
# Cache-Control 头
<IfModule mod_headers.c>
# 图片:1年强缓存
<FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|ico)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
# CSS/JS:1个月
<FilesMatch "\.(css|js)$">
Header set Cache-Control "public, max-age=2592000"
</FilesMatch>
# 字体:1年
<FilesMatch "\.(woff|woff2|ttf|eot)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
# HTML/PHP:不缓存
<FilesMatch "\.(html|php)$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
</FilesMatch>
</IfModule>
# ETag
FileETag MTime Size
# GZIP压缩
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/javascript application/json
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE font/woff font/woff2
AddOutputFilterByType DEFLATE application/font-woff application/font-woff2
</IfModule>
# WebP 内容类型
AddType image/webp .webp