【问题标题】:add a slash at the end of website url using web.config re-write rule?使用 web.config 重写规则在网站 url 末尾添加斜杠?
【发布时间】:2013-11-08 03:10:14
【问题描述】:

我正在开发一个 wordpress 网站。如果网址中不存在,我想在网站网址的末尾添加一个斜杠。

如果有任何人请求此 url:www.mydomain.com/page/subpage,它会务实地转换为 www.mydomain.com/page/subpage/(在 url 末尾附加一个斜杠)。我想要这个,因为当用户请求 www.mydomain.com/page/subpage url 时,它会给我 url not found 错误。

对于 url 重写,我在 web.config 文件中使用以下规则:

web.config 规则:

<rule name="Add trailing slash" stopProcessing="true">  
  <match url="(.*[^/])$" />  
  <conditions>  
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />  
  </conditions>  
  <action type="Redirect" redirectType="Permanent" url="{R:1}/" />  
</rule>

提前致谢。

【问题讨论】:

  • 什么不起作用?

标签: php wordpress iis-7 url-rewriting web-config


【解决方案1】:

试试这个

示例 - 将所有没有尾随斜杠的网址重定向到带有尾随斜杠的网址

创建一个 .htaccess 重写规则

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !example.php
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

【讨论】:

    猜你喜欢
    • 2010-10-13
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 2011-08-21
    相关资源
    最近更新 更多