重写的.htaccess要强调hypens,条状延伸,与放;删除尾随下划线 [英] .htaccess rewrite underscores to hypens, strip extension, & remove trailing underscores

查看:207
本文介绍了重写的.htaccess要强调hypens,条状延伸,与放;删除尾随下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转换我的博客从活字印刷到字press.There的几千项,幸运的是我能够保持(几乎)相同的永久链接。

I'm converting my blog from movable type to wordpress.There are several thousand entries, and thankfully I am able to keep (almost) the same permalinks.

我知道,有一些聪明的的.htaccess 巫术,我应该能够重定向我的网址,但我不能为我的生活弄清楚什么的声明(S)应be.I有超过20000个条目,因此重定向在个别网页上是不理想的。

I know that with some clever .htaccess wizardry, I should be able to redirect my URLs, but I can't for the life of me figure out what the statement(s) should be.I have over 20,000 entries, so redirects on individual pages is not ideal.

这就是我需要做的:

我有这样一串网址:

http://example.com/posttype/2013/05/04/ story_name_and_such_.php

我需要:

if(extension is .php) {
  1. Convert underscores to hypens in the filename.
  2. Remove the file extension.
  3. Remove trailing hypens.
}

以上最终会这样:

The above would end up as such:

http://example.com/posttype/2013/ 5月4日/故事名称和这样

没有人这样做类似这样的东西吗?我真的可以用帮助在这一个!

Anyone done something similar to this? I could really use the help on this one!

推荐答案

如何在你的文档根这样的事情,在htaccess文件:

How about something like this, in the htaccess file in your document root:

RewriteEngine On

RewriteRule ^(.+)_(.+)\.php /$1-$2.php [L,R=301]
RewriteRule ^(.+)_\.php /$1.php [L,R=301]
RewriteRule ^(.+)\.php /$1 [L,R=301]

这篇关于重写的.htaccess要强调hypens,条状延伸,与放;删除尾随下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆