Apache mod rewrite,将旧应用程序的URL转换为新应用程序

Apache mod rewrite,将旧应用程序的URL转换为新应用程序,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有一个修改的问题要解决,我决不是一个专家。我相信我已经很接近了,但还不是很接近 我有一个旧的应用程序,应用程序的文档根位于 ,并使用 或类似的。我需要mod rewrite才能使用 以及使用 此外,新应用程序还有一套用于处理短URL的重写规则: RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l RewriteRule

我有一个修改的问题要解决,我决不是一个专家。我相信我已经很接近了,但还不是很接近

我有一个旧的应用程序,应用程序的文档根位于 ,并使用 或类似的。我需要mod rewrite才能使用 以及使用

此外,新应用程序还有一套用于处理短URL的重写规则:

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.*)$ - [NC,L]
RewriteRule ^(.*)$ index.php [QSA,L]
我目前拥有的是:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^IDN=$1
RewriteRule ^/PlantImages/ImageData\.asp index.php?mod=media&func=display&ot=medium&slug=$1

RewriteRule ^PlantImages/ index.php?mod=media&func=view&ot=collection&tpl=tree

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.*)$ - [NC,L]
RewriteRule ^(.*)$ index.php [QSA,L]

我确实离工作很近,但不是很近。注释掉第一个条件和规则后,第二个(PlantImages/)将正确重定向。但是如果没有注释掉,第一个就不会重定向,css被破坏,第二个也被破坏。

您需要在查询字符串匹配中创建一个捕获组,而不是反向引用:

RewriteCond %{QUERY_STRING} ^IDN=([^&]+)
RewriteRule ^/PlantImages/ImageData\.asp index.php?mod=media&func=display&ot=medium&slug=%1
然后用
%1
而不是
$1
反向引用分组

然后,您需要在第二个规则的模式中使用
$

RewriteRule ^PlantImages/$ index.php?mod=media&func=view&ot=collection&tpl=tree

仍然不起作用。第一条规则导致页面加载,就好像它找不到页面一样,而第二条规则与以前没有任何区别。查看rewritelog,似乎样式表的相对URI前面有“PlantImages”。