2016-08-31 12 views
6

पर रीडायरेक्ट करता है मैं वेब ऐप के साथ एज़ूर क्लाउड का उपयोग करता हूं और nodejs पर मेरा सर्वर पक्ष लिखा जाता है। जब वेब ऐप को http अनुरोध प्राप्त होता है तो मैं अनुरोध को https पर रीडायरेक्ट करना चाहता हूं, मुझे समाधान मिला। मैं डाल कि rules टैगAzure वेब ऐप http को https

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

समस्या जब मैं ब्राउज़र "https://myURL.com" यह मुख्य स्क्रीन पर अनुप्रेषित में टाइप हर चीज ठीक है, लेकिन जब मैं https बदलने के लिए अंदर मेरे web.config फाइल करने के लिए http "http://myURL.com" यह https://myURL.com/ पर पुन: निर्देशित "और यूआरएल में जोड़ें" bin/www "के अनुसार कि यूआरएल की तरह दिखता है" http://myURL.com/bin/www ", प्रतिक्रिया है:। पेज नहीं मिल रहा है

सवाल यह है कि एक रीडायरेक्ट करने के लिए है यूआरएल में जोड़े गए डेटा के बिना यूआरएल साफ़ करें?

मेरी web.config फ़ाइल का हिस्सा:

<rewrite> 
     <rules> 
     <!-- Do not interfere with requests for node-inspector debugging --> 
     <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="^bin/www\/debug[\/]?" /> 
     </rule> 
     <!-- First we consider whether the incoming URL matches a physical file in the /public folder --> 
     <rule name="StaticContent"> 
      <action type="Rewrite" url="public{REQUEST_URI}" /> 
     </rule> 
     <!-- All other URLs are mapped to the node.js site entry point --> 
     <rule name="DynamicContent"> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" /> 
      </conditions> 
      <action type="Rewrite" url="bin/www" /> 
     </rule> 
     <!-- Redirect all traffic to SSL --> 
     <rule name="Force HTTPS" enabled="true"> 
      <match url="(.*)" ignoreCase="false" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="off" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" redirectType="Permanent" /> 
     </rule> 
     </rules> 
    </rewrite> 
    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it --> 
    <security> 
     <requestFiltering> 
     <hiddenSegments> 
      <remove segment="bin" /> 
     </hiddenSegments> 
     </requestFiltering> 
    </security> 

, जवाब के लिए माइकल धन्यवाद।

+1

मैं समाधान के तुरंत बाद ही है कि बग गायब हो गया था –

उत्तर

3

आर: 1 नियम पैटर्न में back-reference है। आप यूआरएल यहाँ है कि संलग्न:

url="https://{HTTP_HOST}/{R:1}" 

कि बदलते

में
url="https://{HTTP_HOST}" 

https जड़ को एक रीडायरेक्ट में परिणाम चाहिए।

+0

धन्यवाद, एक ही परिणाम ब्राउज़र की कुकी साफ़ कर पाया। –

5

इसके लिए एक नि: शुल्क और मुक्त स्रोत एक्सटेंशन भी है।

  1. अपनी वेब ऐप सेटिंग्स साइडबार पर जाएं, "एक्सटेंशन" टैब पर खोजें और "जोड़ें" पर क्लिक करें।

Extension Tab

    नीचे
  1. स्क्रॉल करें और gregjhogan से HTTPS का को विस्तार पुनर्निर्देशन HTTP पाते हैं।

Add Extension

  1. शर्तें स्वीकार करें।

Accept Terms

  1. पुनः प्रारंभ कार्रवाई तुरंत प्रभावी करने के लिए वेब एप्लिकेशन।

  2. हो गया!

इस एक्सटेंशन के कार्यान्वयन पर अधिक जानकारी के लिए, check the source code on GitHub। सबसे महत्वपूर्ण स्रोत फ़ाइल applicationhost.xdt है।

उद्धरण from GitHub (2017/02/08) (क्रेडिट gregjhogan करने के लिए जाना): नवम्बर 2017 की स्थिति के अनुसार

applicationhost.xdt

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <location path="%XDT_SITENAME%" xdt:Transform="InsertIfMissing" xdt:Locator="Match(path)"> 
     <system.webServer xdt:Transform="InsertIfMissing"> 
      <rewrite xdt:Transform="InsertIfMissing"> 
       <rules xdt:Transform="InsertIfMissing" lockElements="clear"> 
        <rule name="redirect HTTP to HTTPS" enabled="true" stopProcessing="true" lockItem="true"> 
         <match url="(.*)" /> 
         <conditions> 
          <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
          <add input="{WARMUP_REQUEST}" pattern="1" negate="true" /> 
         </conditions> 
         <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
        </rule> 
       </rules> 
      </rewrite> 
     </system.webServer> 
    </location> 
</configuration> 
+0

यह बहुत अच्छा है .. Web.Config rewrite rule मेरे लिए काम नहीं किया, ऐसा किया! –

संबंधित मुद्दे