How to force https on a subddomain only

Discussion in 'DNS/Domain names' started by grewal, Mar 23, 2017.

  1. Hi

    I want to redirect my sub domain http://abc.xyz.com to https://abc.xyz.com and using following in my web.config file, it is not working, can anybody help me?

    Thanks

    <rewrite>
    <rules>
    <clear />
    <rule name="Redirect to https" stopProcessing="true">
    <match url=".abc*" />
    <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://abc.xyz.com/" redirectType="Permanent" appendQueryString="false" />
    </rule>
    </rules>
    </rewrite>
     
  2. Is your subdomain in its own directory or the root? If it's in its own directory, are you using web.config in that specific directory, or in the root?

    Either way, you might try:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Redirect to https" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}" redirectType="Permanent" appendQueryString="false" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    in the root or the subdirectory, depending on how you're set up.
     
    Elshadriel likes this.
  3. Hi Michael

    My subdomain is pointing to some external IP, so i was trying to do it from root web.connfig.
    when i tried your code on root web.connfig it forces my whole application to run from HTTPS, which is not required.

    i want to run iems.satpaulmittalschool.org only as https://iems.satpaulmittalschool.org/

    Please help
    Thanks
     
  4. It looks like you're pointing to the external IP with a DNS A record, so the request for iems.satpaulmittalschool.org won't hit the web server here. DNS will send it directly to the target server, so https would have to be forced on the target server.

    That target IP appears to be running an Apache web server? If that's the case, you would normally do the https redirect with an .htaccess entry rather than a web.config file.

    In .htaccess it would look like this:
    Code:
    RewriteEngine on
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://iems.satpaulmittalschool.org/$1 [R,L]
    That .htaccess file would be in the site's root directory on the target server.
     
    Elshadriel likes this.

Share This Page