【问题标题】:index.php in Wordpress URLsWordpress URL 中的 index.php
【发布时间】:2013-09-11 15:28:44
【问题描述】:

由于我的 WP 安装变幻莫测,我曾经有以下格式的永久链接:

旧格式:http://mysite.org/index.php/%year%/%monthnum%/%day%/%postname%/

当时,“index.php”是使东西正常工作所必需的。我的 WordPress .htaccess 文件是标准的。

最近,我的托管公司将我迁移到另一台服务器。现在旧格式不起作用。没有“index.php”的不同永久链接格式确实有效:

新格式: http://mysite.org/%year%/%month%/%daynum%/%postname%/

由于我的博客和第三方网站上有许多旧格式的旧链接,我想保留旧格式。我尝试在 .htaccess 文件中插入重定向和重写规则,但无济于事。

谢谢!

【问题讨论】:

    标签: wordpress .htaccess url-rewriting


    【解决方案1】:

    你可以添加这条规则:

    RewriteRule ^index.php/(.*)/?$ /$1/ [R=301,L]
    

    WordPress 规则之上:

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    它会将 301 永久重定向从您的旧样式 URL 发送到新样式。

    鉴于您的 .htaccess 具有基本的 WordPress 规则,它看起来像这样:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php/(.*)/?$ /$1/ [R=301,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

    • 哈!这比我想的解决方案还要好。现在旧版 URL 已被转换,但我可以使用不带“index.php”的 URL 发布新帖子,从而将自己永远链接到旧版格式。非常感谢!
    猜你喜欢
    • 2018-07-20
    • 2012-08-19
    • 2013-06-25
    • 1970-01-01
    • 2017-07-18
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    相关资源
    最近更新 更多