简体   繁体   English

mod_rewrite 用于尾随斜杠问题

[英]mod_rewrite for trailing slash problem

I'm pulling my hair out on what should be an insanely simple problem.我正在把头发拉出来解决应该是一个非常简单的问题。 We are running WebSphere IHS (Apache) through an F5 BigIP.我们通过 F5 BigIP 运行 WebSphere IHS (Apache)。 BigIP is doing the https translation for us. BigIP 正在为我们进行 https 翻译。 Our url (changed for web, not valid) is https://superniftyserver.com/lawson/portal .我们的网址(已更改为网络,无效)是https://superniftyserver.com/lawson/portal

When someone types in just that without the slash after portal, Apache assumes "portal" to be a file and not a directory.当有人在门户后没有斜杠输入时,Apache 假定“门户”是一个文件而不是一个目录。 When Apache finds out what it is, it sends the 301 Permanent Redirect.当 Apache 发现它是什么时,它会发送 301 永久重定向。 But since Apache knows only http, it sends the URL as http://superniftyserver.com/lawson/portal/ which then creates problems.但由于 Apache 只知道 http,它会将 URL 作为http://superniftyserver.com/lawson/portal/发送,这会产生问题。

So I tried a server level httpd.conf change for mod_rewrite, this is one of the dozens of combinations I've tried.所以我为 mod_rewrite 尝试了服务器级别的 httpd.conf 更改,这是我尝试过的几十种组合之一。

RewriteEngine on RewriteRule ^/lawson/portal(.*) /lawson/portal/$1 RewriteRule 上的 RewriteEngine ^/lawson/portal(.*) /lawson/portal/$1

I also tried RewriteRule ^/lawson/portal$ /lawson/portal/我也试过 RewriteRule ^/lawson/portal$ /lawson/portal/

Among many other things... What am I missing?在许多其他事情中......我错过了什么?

If you can't get an answer on the RewriteRule syntax, here are two other options for you: Write an custom iRule on BigIp (see F5 DevCentral ) that looks for 301 responses and convert them to SSL;如果您无法获得有关 RewriteRule 语法的答案,这里有两个其他选项供您选择: 在 BigIp 上编写一个自定义 iRule(请参阅F5 DevCentral ),查找 301 响应并将它们转换为 SSL; let the URL pass into your WebSphere server and do a programmatic redirect that sends out HTTPS.让 URL 传递到您的 WebSphere 服务器并执行发送 HTTPS 的编程重定向。 However, because F5 terminates the SSL connection, you have to set a custom header that you configure (see PQ86347 ) so the Java request.getScheme() works as you would expect.但是,由于 F5 终止 SSL 连接,您必须设置您配置的自定义标头(请参阅PQ86347 ),以便 Java request.getScheme() 可以按预期工作。

Fixed!固定的!

SOL6912: Configuring an HTTP profile to rewrite URLs so that redirects from an HTTP server specify the HTTPS protocol SOL6912:配置 HTTP 配置文件以重写 URL,以便来自 HTTP 服务器的重定向指定 HTTPS 协议


Updated: 8/7/07 12:00 AM更新时间:2007 年 8 月 7 日上午 12:00

A ClientSSL virtual server is typically configured to accept HTTPS connections from a client, decrypt the SSL session, and send the unencrypted HTTP request to the web server. ClientSSL 虚拟服务器通常配置为接受来自客户端的 HTTPS 连接、解密 SSL 会话并将未加密的 HTTP 请求发送到 Web 服务器。

When a requested URI does not include a trailing slash (a forward slash, such as /, at the end of the URI), some web servers generate a courtesy redirect.当请求的 URI 不包含尾部斜杠(URI 末尾的正斜杠,例如 /)时,某些 Web 服务器会生成礼貌重定向。 Without a trailing slash, the web server will first treat the resource specified in the URI as a file.如果没有尾部斜杠,Web 服务器将首先将 URI 中指定的资源视为文件。 If the file cannot be found, the web server may search for a directory with the same name and if found, send an HTTP 302 redirect response back to the client with a trailing slash.如果找不到该文件,则 Web 服务器可能会搜索具有相同名称的目录,如果找到,则将带有尾部斜杠的 HTTP 302 重定向响应发送回客户端。 The redirect will be returned to the client in HTTP mode rather than HTTPS, causing the SSL session to fail.重定向将以 HTTP 模式而不是 HTTPS 模式返回给客户端,从而导致 SSL 会话失败。

Following is an example of how an HTTP 302 redirect response causes the SSL session to fail:以下是 HTTP 302 重定向响应如何导致 SSL 会话失败的示例:

· To request an SSL session, a user types https://www.f5.com/stuff without a trailing slash. · 要请求 SSL 会话,用户键入https://www.f5.com/stuff后不带斜杠。

· The client browser sends an SSL request to the ClientSSL virtual server, which resides on the BIG-IP LTM system. · 客户端浏览器向位于 BIG-IP LTM 系统上的 ClientSSL 虚拟服务器发送 SSL 请求。

· The BIG-IP LTM system then decrypts the request and sends a GET /stuff command to the web server. · BIG-IP LTM 系统然后对请求进行解密并向网络服务器发送一个 GET /stuff 命令。

· Since the /stuff file does not exist on the web server, but a /stuff/ virtual directory exists, the web server sends an HTTP 302 redirect response for the directory, but appends a trailing slash to the resource. · 由于 Web 服务器上不存在 /stuff 文件,但存在 /stuff/ 虚拟目录,因此 Web 服务器为该目录发送 HTTP 302 重定向响应,但在资源的尾部附加一个斜杠。 When the web server sends the HTTP 302 redirect response, it specifies HTTP (not HTTPS).当 Web 服务器发送 HTTP 302 重定向响应时,它指定了 HTTP(不是 HTTPS)。

· When the client receives the HTTP 302 redirect response, it sends a new request to the BIG-IP LTM virtual server that specifies HTTP (not HTTPS). · 当客户端收到 HTTP 302 重定向响应时,它会向指定 HTTP(不是 HTTPS)的 BIG-IP LTM 虚拟服务器发送一个新请求。 As a result, the SSL connection fails.因此,SSL 连接失败。

Configuring an HTTP profile to rewrite URLs配置 HTTP 配置文件以重写 URL

In BIG-IP LTM version 9.x you can configure an HTTP profile to rewrite URLs so that redirects from an HTTP server specify the HTTPS protocol.在 BIG-IP LTM 版本 9.x 中,您可以配置 HTTP 配置文件以重写 URL,以便来自 HTTP 服务器的重定向指定 HTTPS 协议。 To do so, perform the following procedure:为此,请执行以下过程:

  1. Log in to the Configuration utility.登录到配置实用程序。

  2. Click Local Traffic.单击本地流量。

  3. Click Profiles.单击配置文件。

  4. Click the Create button.单击创建按钮。

  5. Type a name for the profile.键入配置文件的名称。

  6. Choose http from the Parent Profile drop-down menu.从父配置文件下拉菜单中选择 http。

  7. Under Settings, set Redirect Rewrite to All, Matching, or Nodes, depending upon your configuration在设置下,将重定向重写设置为全部、匹配或节点,具体取决于您的配置

For example:例如:

o Choose All to rewrite any HTTP 301, 302, 303, 305, or 307 redirects to HTTPS o 选择全部以将任何 HTTP 301、302、303、305 或 307 重定向重写为 HTTPS

o Choose Matching to rewrite redirects when the path and query URI components of the request and the redirect are identical (except for the trailing slash) o 选择匹配以在请求和重定向的路径和查询 URI 组件相同时重写重定向(尾部斜杠除外)

o Choose Node to rewrite redirects when the redirect URI contains a node IP address instead of a host name, and you want the system to change it to the virtual server address o 当重定向 URI 包含节点 IP 地址而不是主机名并且您希望系统将其更改为虚拟服务器地址时,选择 Node to rewrite redirects

  1. Click Finished.单击完成。

You must now associate the new HTTP profile with the ClientSSL virtual server.您现在必须将新的 HTTP 配置文件与 ClientSSL 虚拟服务器相关联。

Try this:尝试这个:

# Trailing slash problem
RewriteCond    %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule    ^(.+[^/])$           https://<t:sitename/>$1/ [redirect,last]
LoadModule rewrite_module                modules/mod_rewrite.so

确保该行位于 httpd.conf 文件中的某个位置

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/lawson/portal$ RewriteRule ^(.*)$ https://superniftyserver.com/lawson/portal/ [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM