2009-08-22 43 views
1

首先看看这个网址在IIS或Apache参数:传递不存在的目录作为

https://stackoverflow.com/questions/tagged/xoxoxo/

此目录不存在,但不知何故,计算器可以传递最后一个目录作为参数传递给他的基地脚本。

这样做可以配置IIS或Apache吗?怎么样?

+0

当我打开那个链接我刚刚得到的页面标题,没有内容。 – pipTheGeek 2009-08-22 09:47:08

+0

不,你可以在右边看到: 0问题标签 – EBAG 2009-08-22 10:01:44

+0

也看到该页面意味着这个不存在的目录是以某种方式处理 – EBAG 2009-08-22 10:02:55

回答

5

这种行为背后的机制被称为URL重写,可以在实现阿帕奇mod_rewrite - 模块和IIS与任何Helicons ISAPI_Rewrite Lite(或由赫利提供的非自由选择之一)为IIS 5.1和或与Microsoft URL Rewrite Module for IIS 7

例如,以下设置将确保在现有文件或目录中无法匹配的每个请求都将被传输到index.php文件。

mod_rewrite(你的文档根目录.htaccess或某处你httpd.conf

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] // IF is file (with size > 0) 
RewriteCond %{REQUEST_FILENAME} -l [OR] // OR is symbolic link 
RewriteCond %{REQUEST_FILENAME} -d  // OR is directory 
RewriteRule ^.*$ - [NC,L]    // DO NOTHING 
RewriteRule ^.*$ index.php [NC,L]  // TRANSFER TO index.php 

的ISAPI_Rewrite精简版(在你的IIS设置相应的对话框)

// uses same syntax as mod_rewrite 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

微软URL重写模块(在你的web.config文档根目录或seomewhere配置树)

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <clear /> 
       <rule name="MatchExistingFiles" stopProcessing="true"> 
        <match url="^.*$" /> 
        <conditions logicalGrouping="MatchAny"> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="false" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" ignoreCase="false" /> 
        </conditions> 
        <action type="None" /> 
       </rule> 
       <rule name="RemapMVC" stopProcessing="true"> 
        <match url="^.*$" /> 
        <conditions logicalGrouping="MatchAll" /> 
        <action type="Rewrite" url="index.php" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration>