使用mod_rewrite和.htaccess将example.com/index.php / ...重写为example.com / ...

时间:2016-05-07 08:25:40

标签: .htaccess mod-rewrite

我正在将我的网站从Wordpress迁移到Jekyll,我希望保持网址的正常运行。我的想法是为此使用.htaccess文件并将其放在网站的根目录中。但不幸的是,在尝试了几个教程并生成它之后似乎没有用。

旧网址具有以下格式

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

除其他外,我尝试过这个看起来不错的例子,但它实际上是在我网站上的所有页面上显示错误信息:)

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index.php.*$ http://example.com/ [R=301,L]

我认为应该使用以example.com/index.php开头的所有网址,并以example.com/开头,但显然情况并非如此。

1 个答案:

答案 0 :(得分:1)

重定向

  • 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
相关问题