IIS 7 URL重写 [英] IIS 7 URL Rewriting
问题描述
我已经将这个工作了几个小时,现在试图使它工作。我有一个CodeIgniter网站,该网站过去可以正常运行在Apache服务器上。我使用Apache URL Rewriter作为URL,以便隐藏index.php。由于某种原因,我无法在IIS上使用它。我已经对其进行了Google搜索,并提出了几种不同的选择,但是有些要么无法正常工作,要么将我重定向到了我的根目录。
I have been working this one for a few hours now trying get this to work. I have a CodeIgniter website that use to be on an Apache server running fine. I was using the Apache URL Rewriter for the URL in order to hide the index.php. For some reason I cannot get this to work on IIS. I have Googled it and came up with several different options but some either didn't work or redirected me to my root directory.
我正试图像这样重写URL
http://domain.com/v2.3.1/index.php/test
I am trying to rewrite the URL like so
http://domain.com/v2.3.1/index.php/test
下面是 web.config
文件的规则:
<rewrite>
<rules>
<rule name="Clean URL" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
当前配置会将我发送回我的根目录。我的网站位于以下示例URL:
The current configuration will send me back to my root directory. My website is located at an example URL below:
http://domain/v2.3.1
-这将带我到我的主页
http://domain/v2.3.1
- This will bring me to my main page
但是
http:// domain / v2 .3.1 / test
-将带我回到 http:// domain
,但URL从未从 http:/更改/domain/v2.3.1/test
http://domain/v2.3.1/test
- Will take me back to http://domain
but the URL never changes from http://domain/v2.3.1/test
推荐答案
规则没有任何变化。我把规则放在错误的目录中。网站根目录不是域根目录,它位于子目录中。使用IIS,您需要将 web.config
放在要重写URL的同一目录中。
Nothing changed on the rule. I had the rule in the wrong directory. The website root was not the domain root, it was in a sub directory. With IIS you need to have the web.config
in the same directory that you are wanting to rewrite the URL.
经过几个小时的敲打,我终于明白了。
After several hours of banging my head I finally figured it out.
这篇关于IIS 7 URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!