【问题标题】:mod rewrite, transform urls for old app to new appmod重写,将旧应用程序的url转换为新应用程序
【发布时间】:2013-11-09 10:00:46
【问题描述】:

我有一个模组重写问题要解决,我绝不是专家。我相信我已经接近了,但还不是很接近。

我有一个旧应用程序,该应用程序的文档根位于 http://doma.in/PlantImages/,并且特定页面是使用加载的 http://doma.in/PlantImages/ImageData.asp?IDN=01-002h 或类似的。我需要 mod rewrite 才能使用 http://doma.in/index.php?mod=media&func=view&ot=collection&tpl=tree 和使用 http://doma.in/index.php?mod=media&func=display&ot=medium&slug=01-002h 的单个页面

更重要的是,新应用有一套现有的处理短 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坏了,第二个也坏了。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

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

    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
    

    【讨论】:

    • 还是不行。第一条规则导致页面加载好像找不到页面,第二条显示与之前没有区别。查看重写日志,样式表的相关 URI 似乎都以“PlantImages”开头。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2013-09-28
    • 1970-01-01
    • 2013-02-07
    • 2011-07-16
    相关资源
    最近更新 更多