使用.htaccess重定向URL,不带尾部帖子id



我有一个场景,需要使用.htaccess 重定向所有URL或wordpress,而不跟踪post-id

示例:

https://example.com/chapter/subject-origin-chapter/1223到https://example.com/chapter/subject-origin-chapter

https://example.com/subject/subject-physics/38957到https://example.com/subject/subject-physics

其他解决方案也受到欢迎。

当前.htaccess是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我找到了一个解决方案:

RewriteRule ^chapter/([a-zA-Z0-9-]+)/(d+)$ /chapter/$1 [L, R=301]
RewriteRule ^subject/([a-zA-Z0-9-]+)/(d+)$ /subject/$1 [L, R=301]

最新更新