【问题标题】:Explain mod_rewrite issue解释 mod_rewrite 问题
【发布时间】:2015-01-20 21:27:00
【问题描述】:

我将我的 wordpress 网站的永久链接结构从 /%postname%.html 更改为 /%postname%/。我想将所有旧 url 重定向到新结构,所以我在我的 .htaccess 中添加了以下内容:RedirectMatch 301 ^/([^/]+).html$ /$1/。所以现在我的 .htaccess 看起来像这样:

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

它可以很好地重定向我的旧帖子网址,但它会弄乱我的主页。如果我尝试转到我网站的根目录/,它会重定向到/index/

有人可以解释为什么会发生这种情况以及如何解决吗?

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite redirect


    【解决方案1】:

    我想通了。我更改了我的 DirectoryIndex,所以它直接进入 index.php:

    DirectoryIndex index.php
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RedirectMatch 301 ^/([^/]+).html$ /$1/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多