如何通过重写删除URL内的扩展名

时间:2018-04-06 16:55:26

标签: regex url-rewriting

如何从网址中删除扩展程序.php

https://example.com/file.php/a/b/b

当文件在url的末尾时,我使用:

RewriteRule ^(.*)\.php/?$ $1 [R=301,L]

但文件是在midle,我该怎么做?

2 个答案:

答案 0 :(得分:0)

您可能想要使用的是字边界,即:

\b

https://www.regular-expressions.info/wordboundaries.html

RewriteRule ^(.*)\.php\b $1 [R=301,L]

简短摘要是单词边界是零宽度非字母/数字。在你的情况下,斜线或线的结尾。这听起来像你在寻找。

答案 1 :(得分:0)

使用此标尺选择网址

中的所有 .php
RewriteRule \S[php]\S(?=\/) $1 [R=301,L]

https://regex101.com/