通过.htaccess重定向我的旧网址不起作用

问题描述 投票:0回答:1

我正在尝试更改我的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,但也许我遗漏了什么?

regex .htaccess redirect mod-rewrite syntax
1个回答
0
投票

已解决。

正确的语法是:

RewriteRule ^.*/.*/.*/(.*) /article/$1 [R=301,NC,L]
© www.soinside.com 2019 - 2024. All rights reserved.