重写example.com/index.php/。。。到example.com/。。。使用mod_rewrite和.htaccess

重写example.com/index.php/。。。到example.com/。。。使用mod_rewrite和.htaccess,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我正在将我的网站从Wordpress迁移到Jekyll,我想保持URL正常工作。我的想法是为此使用.htaccess文件,并将其放在站点的根目录中。但不幸的是,在尝试了几篇教程并生成了一些代码后,它似乎不起作用 旧URL具有以下格式 http://example.com/index.php/2016/05/07/title-of-the-blog-post/ 新URL具有以下格式: http://example.com/2016/05/07/title-of-the-blog-post.htm

我正在将我的网站从Wordpress迁移到Jekyll,我想保持URL正常工作。我的想法是为此使用.htaccess文件,并将其放在站点的根目录中。但不幸的是,在尝试了几篇教程并生成了一些代码后,它似乎不起作用

旧URL具有以下格式

http://example.com/index.php/2016/05/07/title-of-the-blog-post/
新URL具有以下格式:

http://example.com/2016/05/07/title-of-the-blog-post.html
在其他例子中,我尝试了这个对我来说不错的例子,但它实际上会使我网站上的所有页面显示一条错误消息:)

我认为应该采用所有以
example.com/index.php开头的URL,并使它们以
example.com/
开头,但显然不是这样。

重定向

  • http://example.com/index.php/2016/05/07/title-of-the-blog-post/

  • http://example.com/2016/05/07/title-of-the-blog-post.html
您可以使用以下规则:

RewriteEngine on
RewriteRule ^index\.php/(.+)$ http://example.com/$1.html [NE,L,R]
或者,您也可以像这样使用
mod_alias

RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html

那一个非常接近!我需要添加一个额外的斜杠来让它工作。在我看到你的例子后,它看起来很简单:)<代码>重写规则^index\.php/(.+)/$http://example.com/$1.html[NE、L、R]
RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html