是否有可能取代一些URL的正斜线(/)在一个RewriteRule点(。)? 它不必完全用RewriteRule来完成,但绝对不能用脚本来完成。
例1:
INPUT:/document/my/document.html OUTPUT:/document-my.document.html
例2:
INPUT:/document/depth/of/path/can/vary.html 输出:/document-depth.of.path.can.vary.html
我想你可以用迭代的方法做到这一点。 “可变数量的replace”意味着您必须多次使用相同的规则,每个replace一个“/”。
尝试这个:
RewriteRule ^/([^/]+)/(.*)$ /$1.$2 [N]
一些细节:
/ +任何东西+ / +任何东西 /明确,因为它将永远在那里,不能被replace为. [N]标志表示: Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. (来自Apache mod_rewrite文档 ) 什么工作(感谢乔纳森克拉克的答案):
RewriteCond %{REQUEST_URI} ^/document.* RewriteRule ^/([^/]+)/(.*)$ /$1.$2 [N] RewriteRule ^/document\.(.*)\.html /document-$1 [L]