简体   繁体   English

从 IIS ISAPI 重写迁移到 Apache mod_rewrite

[英]Moving from IIS ISAPI rewrite to Apache mod_rewrite

I've seen few people have asked this on here already, but none of the solutions provided worked for me so far.我已经看到很少有人在这里问过这个问题,但到目前为止提供的解决方案都没有对我有用。

We have always been developing for the IIS ISAPI rewrite (on Windows) and suddenly one of the clients decided to place the project on the Linux server running Apache.我们一直在为 IIS ISAPI 重写(在 Windows 上)进行开发,突然其中一个客户决定将该项目放在运行 Apache 的 Linux 服务器上。 As a result some of the rules are no longer working.结果,一些规则不再起作用。

Example of an ISAPI rewrite rule: ISAPI 重写规则的示例:

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^login/?([^/]*)([^/]*)$ /login.cfm?msg=$1&$2 [L,QSA]
RewriteRule ^login.cfm$  /login/ [R=301,L,NC]

login.cfm is an actual existing page and not dynamically generated based on template. login.cfm 是一个实际存在的页面,不是基于模板动态生成的。

Could someone help me how to translate this for the Apache mod_rewrite please?有人可以帮助我如何为 Apache mod_rewrite 翻译这个吗? Currently the rule creates an infinitive loop and the output is:目前该规则创建一个不定式循环,输出为:

login/?msg=&&msg=&&msg=&&msg=&&msg=&&msg... (till the limit of the url length) login/?msg=&&msg=&&msg=&&msg=&&msg=&&msg...(直到url长度限制)

Safe to say the page is not found either so it doesn't even check whether the file with such name exists.可以肯定地说,也找不到该页面,因此它甚至不检查具有此类名称的文件是否存在。

The page could be /login or /login/wrong so the rule should recognize both cases.该页面可能是 /login 或 /login/wrong,因此规则应识别这两种情况。

You can use these rules in your site root .htaccess:您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /login\.cfm\?msg=([^\s&]*)\s [NC]
RewriteRule ^ /login/%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^login(?:/([\w-]+))?/?$ login.cfm?msg=$1 [L,QSA,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM