【发布时间】:2020-04-20 00:33:53
【问题描述】:
我正在尝试将我的 htaccess 文件更改为重定向,但它不起作用,我不知道为什么。如果这很重要,旧网址现在会给出 404。
Old structure: https://www.example.com/category/tag/id/slug
New structure: https://www.example.com/article/slug
我想捕获蛞蝓并将其放入新结构中。我的 htaccess 文件如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^/.*/.*/.*/(.*)$ /article/%1 [R=301,NC,L]
</IfModule>
我在想我最后的 RewriteRule 是正确的,但也许我遗漏了什么?
【问题讨论】:
-
我在使用 %1 而不是 $1 时看到了一个错误,但它仍然无法正常工作。
标签: regex .htaccess redirect mod-rewrite syntax