创建一个动态的RewriteRule

时间:2013-09-27 20:43:09

标签: apache mod-rewrite

是否可以创建一个包含动态参数(部分网址)的RewriteRule?

这是现有的重写:

RewriteCond  %{SERVER_NAME}  ^dashdiscovery-dev.site.com
RewriteRule ^/?auth/?$ https://osso-stg.site.com/opensso/idpssoinit?realm=/sitenet&iPSPCookie=yes&RelayState=app=tableau,appURI=/views&NameIDFormat=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress&metaAlias=/sitenet/externalidpv2&spEntityID=server.site.com&binding=urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST  [L,R]

我需要获取所请求的完整地址并将其动态地写入Rewrite appURI =参数。

这样的事情:

RewriteCond  %{SERVER_NAME}  ^dashdiscovery-dev.site.com(/view/page7)
    RewriteRule ^/?auth/?$ https://osso-stg.site.com/opensso/idpssoinit?realm=/sitenet&iPSPCookie=yes&RelayState=app=tableau,appURI=(**/view/page7**)&NameIDFormat=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress&metaAlias=/sitenet/externalidpv2&spEntityID=server.site.com&binding=urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST  [L,R]

但我还需要将其重定向到just / views如果网站名称后面没有任何其他参数RewriteCond%{SERVER_NAME} ^ dashdiscovery-dev.site.com

编辑以提供有关预期网址的更多信息:

dashdiscovery-dev.site.com

  • 需要在Rewrite
  • 中有appURI = / views

dashdiscovery-dev.site.com/views/ResourceManagerDashboardv10-3-15-13_bkup/4DemandvsBooking

  • 需要在Rewrite中有appURI = / views / ResourceManagerDashboardv10-3-15-13_bkup / 4DemandvsBooking

dashdiscovery.site.com/views/OpsPipeline/PipelineDash

  • 需要在Rewrite中有appURI = / views / OpsPipeline / PipelineDash

并非所有网址都只是过去/视图的2个级别,但他们应该都有/视图

1 个答案:

答案 0 :(得分:0)

dashdiscovery-dev.site.com

RewriteCond %{HTTP_HOST} ^dashdiscovery-dev\.site\.com$ [NC]
RewriteRule ^/?$ https://osso-stg.site.com/opensso/idpssoinit?realm=/sitenet&iPSPCookie=yes&RelayState=app=tableau,appURI=/views&NameIDFormat=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress&metaAlias=/sitenet/externalidpv2&spEntityID=server.site.com&binding=urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST  [L,R]

其他一切:

RewriteCond %{HTTP_HOST} ^dashdiscovery-dev\.site\.com$ [NC]
RewriteRule ^/?(views/.*)$ https://osso-stg.site.com/opensso/idpssoinit?realm=/sitenet&iPSPCookie=yes&RelayState=app=tableau,appURI=/$1&NameIDFormat=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress&metaAlias=/sitenet/externalidpv2&spEntityID=server.site.com&binding=urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST  [L,R]

规则目标中的$1反向引用(views/.*)正则表达式匹配。