UrlRewriteFilter: www and https redirect

房东的猫 提交于 2019-12-11 04:52:46

问题


I am using Tuckey UrlRewriteFilter to force users to go to the 'www' and 'https' version of my web. I mean next 3 URLs must redirect to https://www.myweb.com

  • http://www.myweb.com
  • http://myweb.com
  • https://myweb.com

The problem comes with the last one, I cannot find the solution to put 'www' for 'https'. I have the next rule that makes 2 first cases work without problems:

  <rule>
    <name>Domain Name Check</name>
    <condition name="host" operator="equal">myweb.com$</condition>
    <condition type="scheme" operator="equal">^http$</condition>
    <from>^(.*)$</from>
    <to type="permanent-redirect">https://www.myweb.com$1</to>
  </rule>

This one of course does not apply for the third case. If I try a similar rule for the third case like the following, it doesn't work either (I don't know why):

  <rule>
    <name>Domain Name Check</name>
    <condition name="host" operator="equal">myweb.com$</condition>
    <condition type="scheme" operator="equal">^https$</condition>
    <from>^(.*)$</from>
    <to type="permanent-redirect">https://www.myweb.com$1</to>
  </rule>

Could you please help me to figure out the rule for the third case?

Thank you.


回答1:


The problem was not the filter but my certificate. I issued my certificate for www.myweb.com but not for myweb.com so https://myweb.com request didn't reach my server, the browser detected the certificate was not valid and blocked the process.

I just issued my certificate for https://myweb.com and modified my Tuckey rule as you can see below. Now https://www.myweb.com is the only URL users can use.

  <rule> 
    <name>Domain Name Check</name>
    <condition type="request-url" operator="equal">(^http://myweb.com|^http://www.myweb.com|^https://myweb.com)</condition>
    <from>^(.*)$</from>
    <to type="redirect">https://www.myweb.com$1</to>
  </rule>


来源:https://stackoverflow.com/questions/44953464/urlrewritefilter-www-and-https-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!