标签: rewrite

在配置 XML 中找不到 IIS 重写规则

我通过 IIS 管理器 GUI 创建了一个新的 URL 重写规则。但是,当我浏览到站点配置 XML 文件时,即使我已经确认重写工作正常,我也看不到任何重写规则。我原以为重写 GUI 会在配置文件中生成相应的 XML。这不是它的工作原理吗?

iis rewrite iis-7

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

Nginx 重写而不重定向

我希望 urldomain.com/foo-111从目录加载内容/bar/111但不更改 url。

我创建了一个重写规则,但它没有加载正确目录的内容,而是 301 重定向到 domain.com/bar/111

我的服务器配置

server {
  listen 80;
  server_name domain.com;

  location / {
      root /var/www/domain.com;
      index index.html index.htm;
      rewrite ^/foo-(.*)$ /bar/$1 break;
      try_files $uri $uri/ =404;
  }
}
Run Code Online (Sandbox Code Playgroud)

rewrite nginx

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

使用 IIS7 作为反向代理

我正在家里设置一个服务器来托管一些小网站。其中之一是基于 .NET 并且需要 IIS,其他是基于 PHP 并且需要 Apache。所以,我在我的服务器上安装了 IIS 7 和 Apache 2.2.x,IIS 在端口 80 上,Apache 在端口 8080 上运行。

我想将 IIS 设置为反向代理,将 Apache 站点的请求转发到端口 8080 并根据主机标头为 .NET 站点本身的请求提供服务。像这样:

www.mydotnetsite.com/* -> IIS -> serve from IIS
www.myapachesite.com/* -> IIS -> forward to apache on port 8080
www.myothersite.com/*  -> IIS -> forward to apache on port 8080
Run Code Online (Sandbox Code Playgroud)

我做了一些谷歌搜索,似乎应用程序请求路由功能可以满足我的需要,但我似乎无法让它按照我想要的方式工作。我可以让它将所有流量转发到 Apache 服务器,我可以让它将具有特定 URL 模式的流量转发到 Apache 服务器,但我似乎无法根据主机标头(例如“转发www.apachesite.com 的所有请求 -> localhost:8080")

所以问题是,我将如何配置 ARR 来做到这一点?还是我需要不同的工具?

我也愿意使用 Apache 作为反向代理并将 .NET 站点请求转发到 IIS,如果这样更容易的话(在端口 80 上运行 Apache,在 8080 上运行 IIS)。

rewrite iis-7 web-server apache-2.2

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

RewriteRules 不会以 LAST 标志停止?

我似乎遇到了 Apache 2.2 的 Rewrite 模块(在 FreeBSD 8 上运行)的问题。我的.htaccess文件如下:

Options -Indexes

RewriteEngine on
RewriteRule ^xpaste$ cross.php [L]
RewriteRule ^x([a-f0-9]*)$ cross.php?id=$1 [L]
RewriteRule ^(gen|[a-f0-9]+)$ index.php?$1 [L]
RewriteRule ^(.*)$ index.php [L] 
Run Code Online (Sandbox Code Playgroud)

然而不知何故,最后一条规则覆盖了其他三条规则。一旦我将其注释掉,其他规则就会按预期工作:

  • www.example.com/xpaste 打开 cross.php
  • www.example.com/x132633 打开 cross.php?id=132633
  • www.example.com/gen 打开 index.php?gen

我已经试过的各种组合LNSS=n每个标志RewriteRule,但除非我注释掉最后一条规则,一切都被定向到index.phpRewriteRule一旦找到匹配项,如何让 Apache 停止处理s?

mod-rewrite rewrite .htaccess apache-2.2

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

如何创建这种类型的子域:example.test.domain.com

我设法找到了用于创建子域的重写(我有一个指向我的服务器的通配符域;*.domain.com.

如果我去test.domain.com,它可以很好地横向于:

/var/www/domain.com/www/test/

如果我这样做example.test.domain.com,它应该这样做:

/var/www/domain.com/www/test/example/

这是目录中的另一个test目录。

这是我发现使用的重写,但是我应该如何在这实现两个目录子域?

if ($host !~* ^www\.domain\.domain$) {}
if ($host ~* ^([^.]+)\.domain\.com$) {
    set $auto_subdomain $1;
}
if (-d /var/www/domain.com/www/$auto_subdomain) {}
if (-f /var/www/domain.com/www/$auto_subdomain$uri) {
    rewrite ^(.*)$ /$auto_subdomain$uri;
    break;
}
Run Code Online (Sandbox Code Playgroud)

rewrite nginx subdomain

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

nginx 重定向到另一个域,不要忘记子域

这是一个相当快的:如何重定向到另一个域并仍然转发子域?示例:http : //foo.domainone.com/bar.php -> http://foo.domaintwo.com/bar.php

提前致谢!

rewrite nginx domain subdomain

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

使用 apache 阻止具有特定查询字符串的 url

我有这个网址:

mysite.com?var=var&var2=var2&var3=var3
Run Code Online (Sandbox Code Playgroud)

我想阻止这个特定的 url,但不会以任何方式影响同一基本 url 上的其他查询字符串。

是否有可能做到这一点?

谢谢,

rewrite querystring apache-2.2

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

是否可以将一些查询字符串重写为 HTTPS 并将其他所有内容保留在 HTTP 上?

我正在将查询字符串重写为漂亮的 URI,例如:index.php?q=/en/contact变成/en/contact并且一切正常..

# httpd.conf

# HANDLE THE QUERY
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

甚至可以重写单个查询来强制https和强制其他所有内容http吗?我尝试了许多不同的方法,这些方法通常以无限循环结束。我可以编写一个插件来在 PHP 中执行此操作,但认为在服务器 conf 中处理此问题会更有效。我很乐意提供任何建议。

编辑: 为了澄清,我希望能够将非 SSL 重写为http://example.com/index.php?q=/en/contact启用的 SSLhttps://example.com/en/contact以及每个未/en/contact写入的查询http://example.com/...

mod-rewrite rewrite httpd.conf apache-2.2

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

仅在 nginx 中重写域的根目录

我已经运行了 YOURLS 服务器来为我的公司托管短网址,以便我们可以向我们的客户提供短网址。

我正在使用 nginx,对于域的根目录,如果他们没有使用正确的短 url,我想重定向到我们的网站。因此 example.com/218a 重定向到该短网址指向的任何内容,但 example.com 转到我们的网站 @ domain.com。

现在,我正在使用一个 index.html 页面,它只是一个元刷新来重定向,但我想我应该能够在 nginx 配置中做到这一点,它可能会更好。

如果可能的话,有人可以帮助我以正确的方式在服务器级别实现这一点,而不是使用元刷新吗?

我已经尝试了一些我在这里找到的例子,但它们似乎都不起作用。

这是我的配置文件以供参考。

server {
    server_name www.domain.com;
    return 301 $scheme://domain.com$request_uri;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name http://domain.com;

    location / {
        #YOURLS
        try_files $uri $uri/ /yourls-loader.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass php5-fpm-sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }
}
Run Code Online (Sandbox Code Playgroud)

rewrite nginx

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

IIS 反向代理不使用 ASP.NET 中的 Response.Redirect()

我正在尝试使用此处此处此处的教程设置反向代理。

该站点设置在localhost:8080,反向代理使用localhost:8080/myProxy.

处理标准链接时,一切都很好。我可以查看代理 url 并按预期查看所有内容。从链接localhost:8080/myProxy/default.aspx进入localhost:8080/myProxy/about.aspx预期。

我遇到的问题是,在使用 .NET 的地方Response.Redirect(),url 更改为网站的实际位置,而不是代理。

即链接来自localhost:8080/myproxy/default.aspx-> localhost:8080/about.aspx

请问我该如何解决?

这是我的配置:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <urlCompression doStaticCompression="false" doDynamicCompression="false" 
                    dynamicCompressionBeforeCache="false" />
    <rewrite>
        <rules>
            <rule name="Reverse Proxy to my site" stopProcessing="true">
                <match url="^myProxy/(.*)" />
                <action type="Rewrite" url="http://localhost:8080/{R:1}" />
            </rule>
        </rules>

        <outboundRules>
            <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script"
                       pattern="^http(s)?://localhost:8080/(.*)" />
                <action type="Rewrite" value="/myProxy/{R:2}" /> …
Run Code Online (Sandbox Code Playgroud)

iis rewrite asp.net reverse-proxy iis-7.5

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