开发者

RegularExpression for URL Rewriting

I am using urlrewriter.net and I am trying to make a redirection. So here is the condition,

If the requested url doesn't end with a / (slash) and then add / at the end of the url and redirect to added url.

So if the url is "http://www.something.com/cases" then add / and redirect it to "http://www.something.com/cases/"

I've used code but it didn't work out for me :

<if url="^~/(.+)(/){0}$">
    <redirect url="~/(.+)" to="~/$1/$"开发者_运维问答/>
</if>


I am going to answer my own question here :

I've accomplished this by using this way :

<unless url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.aspx|\.ashx|\.ascx|\.shtml|\.html|\.htm)(\?.+)?)$">
    <if url=".+(?&lt;!/)$">
        <redirect url="(.+)" to="$1/"/>
    </if>
</unless>

If url doesn't end with "/" then it will be redirected to the one which has "/" at the end.

I hope it helps everyone out there.


Can you use the URL Rewrite 2.0 module? You can easily add it there, because the rewrite template for that rule is a built-into the GUI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜