将所有.html重定向到WordPress url,除了一些带有.htaccess的


Redirect all .html to WordPress url except some with .htaccess

我有重写规则来重定向所有以。html结尾的页面,它工作得很好,直到我意识到有文件夹页面,我不需要重定向到WP/php url。

我可以对我的。htaccess做一个异常吗?这是我当前的。haccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule (.+)'.html?$ http://www.example.com/$1/ [R=301,L]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我有一个文件夹,我仍然希望。html工作。

  • www.example.com/htmls/index.html
  • www.example.com/htmls/about.html

我不希望/html/文件夹中的所有文件都被删除。我如何编辑我的。htaccess来做到这一点呢?

谢谢!

您可以使用RewriteCond跳过某个文件夹:

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