【问题标题】:Redirecting my old urls through .htaccess isn't working通过 .htaccess 重定向我的旧网址不起作用
【发布时间】: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


【解决方案1】:

解决了。

正确的语法是:

RewriteRule ^.*/.*/.*/(.*) /article/$1 [R=301,NC,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    相关资源
    最近更新 更多