我对web.config文件没有太多经验,但我要做的是将所有请求重定向到index.php
只添加?url=REQUESTED_PAGE
例如
如果你去了domain.com/about.php?query=string
它会将url重写为domain.com/about/
给用户
但处理网址domain.com/index.php?url=about.php&query=string
这个想法是拥有漂亮的用户友好网址,而index.php可以找出显示用户的页面。 (我正在使用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>
我认为我很接近但仍然没有工作
已解决::!结果!
<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>
答案 0 :(得分:0)
以下是您提出的解决方案:
RewriteRule (.*) index.php?url=$1 [NC,L]
请告诉我它是否有效。
答案 1 :(得分:-1)
您需要使用以下内容创建.htaccess
文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
这会将所有请求(除非是现有文件或目录)传递给index.php
脚本,并且您将能够通过以下操作找出用户在PHP脚本中请求的内容:
<?php
echo $_GET['url'];
?>
因此,您可以在斜杠上拆分传递的url
参数,并将其传递给正确的控制器或其他任何内容。
您不重写现有文件或目录的原因是静态文件,如图像,样式表,JavaScript文件等。否则对做的文件的请求仍将传递给您的{{1脚本。
此外,index.php
之后的QSA
标记允许您继续在网址中使用查询字符串,如果您希望使用搜索表单和分页,如果您更喜欢使用RewriteRule
参数那些也不是URL段。