简体   繁体   English

正则表达式 - 非子域子目录(​​https 或 http)到 https://www

[英]regular expression - non-subdomain subdirectory (https or http) to https://www

I can't seem to nail this regular expression:我似乎无法确定这个正则表达式:

Currently I have:目前我有:

https://example.com/forums/ (1000's of pages) https://example.com/forums/(1000页)

I need to move to我需要搬到

https://www.example.com/ (1000's of pages) https://www.example.com/(1000页)

In addition, if coming in on non-ssl, need to move to ssl.此外,如果进入非ss​​l,则需要移动到ssl。 All via 301. So as another example:全部通过 301。再举一个例子:

http://example.com/forums/somepage.html goes to https://www.example.com/somepage.html http://example.com/forums/somepage.html转到https://www.example.com/somepage.html

and

https://example.com/forums/folder/folder2/anything goes to https://www.example.com/folder/folder2/anything https://example.com/forums/folder/folder2/anything转到https://www.example.com/folder/folder2/anything

Thanks for any help.谢谢你的帮助。

This will match all of your requested routes (good or no good) and reroute them to the good ones you want.这将匹配您请求的所有路线(好或不好),并将它们重新路由到您想要的好路线。 Depending on your regex parser, you may need to throw in some escapes ( \\ ) in there.根据您的正则表达式解析器,您可能需要在其中加入一些转义符 ( \\ )。

s#http(s)?://(www.)?example.com/(forums/)?#https://www.example.com/#g

  http                                       -- match http
      (s)?                                   -- match with or without the s
          ://                                -- match ://
             (www.)?                         -- match with or without www.
                    example.com/             -- match example.com/
                                (forums/)?   -- match with or without forums/

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

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