Regex 修改“重写”;替换“;辅导的
给定以下字符串作为输入:Regex 修改“重写”;替换“;辅导的,regex,apache,mod-rewrite,playframework-2.0,Regex,Apache,Mod Rewrite,Playframework 2.0,给定以下字符串作为输入: /myproject/assets/%2Fmyproject-frontend%2Fstylesheets%2Fbase.css 我如何使用mod_rewrite将其作为输出来实现: /myproject/assets/myproject-frontend/stylesheets/base.css 注意:输入字符串中有一个“/”和“%2F”紧挨着。如果有一种方法可以使用mod rewrite将“%2F”的所有实例替换为“/”,并在assets//myproject前
/myproject/assets/%2Fmyproject-frontend%2Fstylesheets%2Fbase.css
我如何使用mod_rewrite将其作为输出来实现:
/myproject/assets/myproject-frontend/stylesheets/base.css
注意:输入字符串中有一个“/”和“%2F”紧挨着。如果有一种方法可以使用mod rewrite将“%2F”的所有实例替换为“/”,并在assets//myproject前端修复“/”,那么这将是理想的解决方案。以下是我的WIP解决方案:
# If request is for something in "/myproject/assets/myproject-frontend/"
RewriteCond %{REQUEST_URI} ^/myproject/assets/myproject-frontend/ [NC]
# input = /myproject/assets/%2Fmyproject-frontend%2Fstylesheets%2Fbase.css
# Replace all %2F with (single) forward slash
RewriteRule /([%2F]{3})/g \/ [N]
# output = /myproject/assets//myproject-frontend/stylesheets/base.css
# Replace all // with /
RewriteRule (\/\/) \/ [N]
# output = /myproject/assets/myproject-frontend/stylesheets/base.css
# Take the cleaned up input and redirect to the correct URL
RewriteRule ^\/myproject\/assets\/(.*)$ \/myproject\/assets\/$1 [R=301,L]
# output = /myproject/assets/myproject-frontend/stylesheets/base.css