【发布时间】:2011-11-18 19:36:23
【问题描述】:
我对 web.config 文件没有太多经验,但我想做的是将所有请求重定向到 index.php 只添加 ?url=REQUESTED_PAGE
例如
如果你去domain.com/about.php?query=string
它会将 URL 重写为 domain.com/about/ 给用户
但处理 urldomain.com/index.php?url=about.php&query=string
我们的想法是在 index.php 确定向用户显示哪个页面的同时拥有漂亮的用户友好 url。 (嗯,我正在使用 smarty,所以要使用哪个模板)
编辑:我正在寻求有关 web.config 而不是 .htaccsess 的帮助我仅限于托管的客户端,不幸的是,这不是 apache,我能找到的唯一可能与 iis7.5 一起使用或不使用的 mod 是 £ 45 我无法获得资金:(
编辑:我最近的尝试是
<rules>
<rule name="page proc" stopProcessing="true">
<match url="domain.org.uk(.*?)\?(.*)" />
<action type="Redirect" url="{R:0}?url={R:1}?{R:2}" />
</rule>
</rules>
我想我很接近但仍然没有工作
已解决 :: !END 结果!
<rewrite>
<rules>
<rule name="page proc">
<match url="(.*?)\/" />
<action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="false" logRewrittenUrl="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{QUERY_STRING}" pattern="(.*?)(css|js|pdf|jpg|png|gif)" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
【问题讨论】:
-
要在此处获得有用的答案,您需要提供更多详细信息(例如哪个网络服务器)并展示一些研究/解决问题的尝试。如果出现一些具体问题,人们将很乐意为您提供帮助。
-
啊,这不适合 web.config。
-
我使用的是 windows iis 7.5 和 php。我似乎没有困难找到 httpaccsess 文件的重写规则,只是 web.config 仍然是一个谜,主要是我正在努力解决的请求的正则表达式以及我对它们如何工作的有限了解。我已经为 we.config 找到了大量单独的页面重写规则,但我正在寻找更动态的东西,它使用正则表达式来重写 url。
-
这只是一个示例,因为有时 url 中可能存在需要处理的查询字符串。
标签: php url-rewriting web-config