基本概念
- .htaccess 配置文件;如果使用虚拟host则没有
- 特殊的匹配规则 rewritecond
- 通用 正则表达式
-匹配到链接以后执行重写 rewriterule - wordpress会重新定向到index.php
例子
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
更新
20240116 跑通了的设置;需要先在WordPress后台更改固定链接,显示.htaccess无法写入后手动更新virtual host配置
<Directory "/var/www/html">
<FilesMatch \.(html|php)$>
SetHandler "proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost"
</FilesMatch>
Options Indexes FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Require all granted
</Directory>