Url rewriting web.confg重写特定目录的URL

Url rewriting web.confg重写特定目录的URL,url-rewriting,web-config,Url Rewriting,Web Config,我正在尝试为一个项目创建一个类似WP的永久链接。在这方面,我可能离得很远,但以下是我试图实现的目标: 第一条规则是成功删除.php扩展名。因此,类似domain.com/directory/file.php的东西正在变成domain.com/directory/file。太好了 第二条规则旨在检查目录“pages”,使用该目录中的index.php文件,从index.php中删除.php扩展名,并在重写的URL字符串末尾添加一个“slug”(希望我说的都是正确的) 因此,如果有人单击domain

我正在尝试为一个项目创建一个类似WP的永久链接。在这方面,我可能离得很远,但以下是我试图实现的目标:

  • 第一条规则是成功删除.php扩展名。因此,类似domain.com/directory/file.php的东西正在变成domain.com/directory/file。太好了
  • 第二条规则旨在检查目录“pages”,使用该目录中的index.php文件,从index.php中删除.php扩展名,并在重写的URL字符串末尾添加一个“slug”(希望我说的都是正确的)
  • 因此,如果有人单击domain.com/pages/my-slug这样的链接,他们将从“pages”目录中获取索引文件,但URL栏将呈现为domain.com/pages/my-slug(类似于链接)。它基本上是domain.com/pages(index.php)/my slug,其中index.php是呈现的实际文件,但我仍然需要URL末尾的slug

    我希望这在某种程度上是有意义的

    <rule name="Hide PHP Ext">
        <match ignoreCase="true" url="^(.*)"/>
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                <add input="{REQUEST_FILENAME}.php" matchType="IsFile"/>
            </conditions>
        <action type="Rewrite" url="{R:1}.php"/>
    </rule>
    <rule name="Pages"> 
        <match ignoreCase="true" url="^pages/(*)"/>
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                <add input="{REQUEST_FILENAME}.php" matchType="IsFile"/>
            </conditions>
        <action type="Rewrite" url="/pages/index.php/{R:1}"/>
    </rule>
    
    
    
    作为后续行动,我尝试附加以下内容: