标签: url-rewriting

如何使用ASP.Net MVC路由路由图像?

我将我的站点升级为使用传统ASP.Net webforms中的ASP.Net MVC.我正在使用MVC路由将旧.aspx页面的请求重定向到它们的新Controller/Action等效项:

        routes.MapRoute(
            "OldPage",
            "oldpage.aspx",
            new { controller = "NewController", action = "NewAction", id = "" }
        );
Run Code Online (Sandbox Code Playgroud)

这对于页面非常有用,因为它们直接映射到控制器和操作.但是,我的问题是图像请求 - 我不知道如何重定向这些传入的请求.

我需要将http://www.domain.com/graphics/image.png的传入请求重定向到http://www.domain.com/content/images/image.png.

使用该.MapRoute()方法时的正确语法是什么?

c# asp.net asp.net-mvc routing url-rewriting

35
推荐指数
2
解决办法
2万
查看次数

删除HTML或ASPX扩展

在托管的IIS7环境中,我正在寻找使用无扩展名文件名的最简单方法.我只有以下页面:

index.html(或.aspx) - > domain.com gallery.html - > domain.com/gallery videos.html - > domain.com/videos等...

我只有一些页面,我没有动态代码,没什么特别的.我开发我发现所有的例子或我在其他网站使用方法围绕动态内容,网页等,我只是在寻找最简单的解决方案,非常不需要安装任何形式的URL重写模块.最好是,我可以保留.html扩展名,而不是将站点转换为ASP.NET项目,但这是一个选项.

谢谢.

html asp.net iis-7 url-rewriting

35
推荐指数
3
解决办法
6万
查看次数

重定向404错误htaccess后重写URL

所以我知道这看起来有点奇怪,但为了保持一致性,我希望我的所有网址都以这种形式出现:http://domain.com/page/到目前为止,我已经让常规页面正常工作,但我不能似乎让错误页面正常工作.

如果用户访问不存在的页面或目录,我希望浏览器硬重定向到:http://domain.com/404/但是,此目录实际上不存在.错误页面的真实位置将在/pages/errors/404.php下

此外,虽然我不需要所有各种错误(400,401,403,404,500)的确切答案,但我将应用任何方法将所有这些重定向到他们的"正确"URL(例如http) ://domain.com/400/ http://domain.com/500/等)

有任何想法吗?

.htaccess redirect rewrite url-rewriting custom-error-pages

35
推荐指数
3
解决办法
18万
查看次数

34
推荐指数
2
解决办法
9842
查看次数

什么是WCF相当于HttpContext.Current.Request.RawUrl?

我在纯WCF上下文中运行了一些RESTful服务(即没有启用ASP.NET兼容性,因此没有HttpContext.Current可用的对象).

服务的URL在请求开始时使用IHttpModule(在此时确实具有HttpContext并使用其重写HttpContext.Current.RewritePath)来重写,以.svc从URL中删除诸如扩展之类的内容.

但是,我需要访问WCF基础结构中请求的原始URL.是否有一个相当于HttpContext.Current.Request.RawUrlOperationContextWebOperationContext类哪儿了吗?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL而不是原始的URL.

wcf url-rewriting httpcontext operationcontext weboperationcontext

34
推荐指数
1
解决办法
3万
查看次数

IIS url重写角色除了一些网址

我在URL Rewrite中得到了这个角色.用__CODE__to 重写每个请求到网站__CODE__

<rule name="Force HTTPS" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
                </rule>
Run Code Online (Sandbox Code Playgroud)

我需要在此角色中使用其他角色或异常来重写或将特定URL重定向到HTTP.

那可能吗?谢谢.

asp.net iis web-config url-rewriting

33
推荐指数
1
解决办法
4万
查看次数

将规则重写为HTTPS,但在localhost上除外

我使用这里给出的答案作为尝试向我的web.config文件添加重写规则的基础.我希望它匹配任何未在localhost上运行的url以强制https.

这就是我现在所拥有的:

<system.webServer>
  <rewrite> <!-- force https - https://stackoverflow.com/a/15119044/51 -->
    <rules>
      <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
        <match url="^((?!localhost).)*$"/>
        <conditions>
          <add input="{HTTPS}" pattern="^OFF$"/>
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
      </rule>
    </rules>
  </rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

我试图使用负面的环视,以便只匹配url中不包含"localhost"的url.但这不起作用.

那么如何设置此规则才能只重写非localhost网址呢?

regex asp.net-mvc web-config url-rewriting

33
推荐指数
2
解决办法
1万
查看次数

RewriteRule错误:错误的标志分隔符

在我的.htaccess文件中使用这个RewriteRule我得到RewriteRule:Bad flag delimiters,它在浏览器中返回500错误.任何人都可以指出我正确的方向.谢谢.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [NC]

RewriteRule ^dev/(.*)$ http://dev.example.com/$1 [L,R=301, NC]
Run Code Online (Sandbox Code Playgroud)

这是在数字海洋Droplet上的Ubuntu上.

apache ubuntu mod-rewrite url-rewriting digital-ocean

32
推荐指数
2
解决办法
3万
查看次数

为什么我需要使用http.StripPrefix来访问我的静态文件?

main.go

package main

import (
    "net/http"
)

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
    http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)

目录结构:

%GOPATH%/src/project_name/main.go
%GOPATH%/src/project_name/static/..files and folders ..
Run Code Online (Sandbox Code Playgroud)

即使在阅读完文档后,我也无法理解http.StripPrefix这里究竟是做什么的.

1)localhost:8080/static如果删除,为什么我无法访问http.StripPrefix

2)/static如果删除该功能,哪个URL映射到文件夹?

http url-rewriting url-routing go server

32
推荐指数
2
解决办法
1万
查看次数

如何在Java中规范化URL?

URL规范化(或URL规范化)是以一致的方式修改和标准化URL的过程.规范化过程的目标是将URL转换为规范化或规范化URL,以便可以确定两个语法上不同的URL是否相同.

策略包括添加尾部斜杠,https => http等.维基百科页面列出了许多.

在Java中有一个最喜欢的方法吗?也许是一个图书馆(Nutch?),但我是开放的.较小和较少的依赖性更好.

我现在会手工编码,并密切关注这个问题.

编辑:如果他们引用相同的内容,我想积极地规范化以统计URL.例如,我忽略了参数utm_source,utm_medium,utm_campaign.例如,如果标题相同,我会忽略子域.

java url-rewriting

31
推荐指数
2
解决办法
4万
查看次数