网址重写-删除不需要的字符和斜杠

时间:2018-09-27 20:12:23

标签: regex .htaccess mod-rewrite apache2

我需要使用 .htaccess 重写URL,以将所有用户从旧站点地图重定向到新URL。旧的网址如下所示:

http://example.com/a/v/c/document_title1.php
http://example.com/fr/x/1/o/document_title2.php
http://example.com/de/a/a/2/document_title3.php
http://example.com/eng/6/z/z/document_title4.php

我需要保留第一个目录,然后删除所有子目录,包括斜杠和字符(/之间的字母和数字),以便新的URL如下所示:

http://example.com/document_title1.php
http://example.com/fr/document_title1.php
http://example.com/de/document_title2.php
http://example.com/eng/document_title3.php

我尝试了各种在线生成器,总是出现500错误。这是我能做的吗?

1 个答案:

答案 0 :(得分:0)

您可以使用this substitution

模式:(?<=http://example\.com/)(fr/|de/|eng/)?.*(?=document_title\d\.php)

替换为:$1

这几乎肯定需要进行一些调整,但是我正在使用给出的内容。在(fr/|de/|eng/)?这一节中,您需要为每种可能的语言扩展名添加|

相关问题