简体   繁体   English

删除文件名并使用mod_rewrite将正斜杠替换为破折号

[英]Removing file name and swapping forward slashes for dashes with mod_rewrite

Im in the middle of moving my blog from a dynamic site to a static site. 我正在将博客从动态站点转移到静态站点。 As a part of not breaking too many links I'm trying to learn mod_rewrite but getting no where with the following RewriteRule: 作为不中断太多链接的一部分,我尝试学习mod_rewrite,但是使用以下RewriteRule却无济于事:

My old url 我的旧网址

/blog/index.cfm/2012/10/9/My-blog-post

My new url 我的新网址

/blog/2012-10-09-My-blog-post.html

So far I have the following in my vhosts.conf file but its not working 到目前为止,我的vhosts.conf文件中包含以下内容,但不起作用

RewriteRule ([a-zA-Z0-9.]+)(/blog/index.cfm/)([0-9]+)(/)([0-9]+)(/)([0-9]+)(/)([a-zA-Z0-9-]+) $1/blog/$3-$5-$7.html

Any help/pointers would be great 任何帮助/指针都将很棒

First, you only need to bracket (ie capture) things you will be using on the RHS of your rule. 首先,您只需要在规则的RHS中将要使用的内容括起来(即捕获)。 But the problem appears to be that you are only copying the year, month and day to the RHS, but not the My-blog-post . 但是问题似乎是您只将年,月和日复制到RHS,而没有复制My-blog-post Try this: 尝试这个:

RewriteRule ([a-zA-Z0-9.]+)/blog/index.cfm/([0-9]+)/([0-9]+)/([0-9]+)/([a-zA-Z0-9-]+) $1/blog/$2-$3-$4-$5.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM