我们目前在 .htaccess 文件中使用以下规则:
# Convert URLs with underscores into hyphens (excluding any image files)
# Keep scanning the URL as long as there are two hyphens
RewriteRule ^(/?.*[^/]*?)-([^/]*?-[^/]*)$ $1_$2 [N,QSA]
# Replace last hyphen and do a permanent redirect (ending the rewriting operation)
RewriteRule ^(/?.*[^/]*?)-([^/-]*)$ $1_$2 [L,QSA]
但是,我们的网络托管服务商正在关闭我们的网站,并提出以下投诉:
在跟踪这个问题时,我们可以发现第一条规则中 N 的 rewrite FLAG 是循环的。这导致进程以无限循环的形式运行数小时并消耗服务器的资源,因为每个进程使用数百 MB 内存的生成进程。
你们中的任何一个 mod_rewrite 专家有更好的方法来做到这一点吗?
我们只是尝试将文件中的所有下划线替换为 URL 的破折号。不幸的是,我们使用的软件无法生成文件名中带有破折号的文件。
非常感激!
谢谢,道格