URL 重写 - 删除不需要的字符和斜杠
URLs rewrite - Removing unwanted characters and slashes
我需要使用 .htaccess 重写 URL,以将所有用户从旧站点地图重定向到新 URL。旧的 URLs 看起来像这样:
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 错误。这是我能做的吗?
您可以使用this substitution
模式:(?<=http://example\.com/)(fr/|de/|eng/)?.*(?=document_title\d\.php)
替换为:</code></p>
<p>这几乎肯定需要包括一些调整,但我正在处理我得到的东西。在此部分 <code>(fr/|de/|eng/)?
中,您需要为每种可能的语言扩展添加 |
。
我需要使用 .htaccess 重写 URL,以将所有用户从旧站点地图重定向到新 URL。旧的 URLs 看起来像这样:
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 错误。这是我能做的吗?
您可以使用this substitution
模式:(?<=http://example\.com/)(fr/|de/|eng/)?.*(?=document_title\d\.php)
替换为:</code></p>
<p>这几乎肯定需要包括一些调整,但我正在处理我得到的东西。在此部分 <code>(fr/|de/|eng/)?
中,您需要为每种可能的语言扩展添加 |
。