Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess 301 mod重写匹配url模式_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess htaccess 301 mod重写匹配url模式

.htaccess htaccess 301 mod重写匹配url模式,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,这个恐怕超出了我的能力,经过大量的研究和破坏,我来寻求帮助。我有一个URL格式为的网站: example.com/7865/travel-photo/my-mazing-photo 我的客户现在决定在照片上添加一个“s”,因此URL变成: example.com/7865/travel-photos/my-mazing-photo 这一切都很好,仅仅是因为每个URL的数字“7865”都会像“我的精彩照片”一样发生变化。新URL的基本结构需要是: example.com/'number varia

这个恐怕超出了我的能力,经过大量的研究和破坏,我来寻求帮助。我有一个URL格式为的网站:

example.com/7865/travel-photo/my-mazing-photo

我的客户现在决定在照片上添加一个“s”,因此URL变成:

example.com/7865/travel-photos/my-mazing-photo

这一切都很好,仅仅是因为每个URL的数字“7865”都会像“我的精彩照片”一样发生变化。新URL的基本结构需要是:

example.com/'number variable'/travel photos/'article name variable'


那么我的问题是,如何编写一个漂亮的htaccess mod重写规则呢?

感谢Gerben的快速回复。除了我的代码外,我也尝试过同样的代码:RewriteRule^[0-9]+/travel photos/*$$1/travel photo/$2[R=301]不幸的是,我在这两个选项中都没有运气。我不确定这是否重要,但这是一个WordPress博客。我认为你需要的规则是:^[^/]+/travel photo/*$/$1/travel photos/$2[NC,L,R=301]啊哈,所以你想反过来。
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/travel-photos/(.*) $1/travel-photo/$2