In a previous post we showed you how to force a normal HTTP call to HTTPS. Today we’ll show you how to redirect from root to subdirectory.
The default page/homepage in your root directory would normally be displayed when someone makes an HTTP request to your site. But what if you installed an application in a subdirectory and want to use that application as a starting point? For example, WordPress is installed in a subdirectory, and you want the WordPress application to be the default starting point when someone types your URL.
There is sample code available in our Knowledge Base to redirect using .NET code. This requires the page to load and compile before the redirection happens. Now I want to show you redirection using the IIS manager/web.config instead. This should redirect the request faster as the redirection happens as soon as the HTTP request received by IIS.
Using IIS7 manager, connect to IIS and navigate to the URL rewrite module. Add a blank rule and name it as you wish. Only two variables are needed; match URL pattern and actions.
The parameters are as follows:
Match URL section:
Requested URL : Matches the pattern
Using : Regular Expression
Pattern : ^$
Action section:
Action Type : redirect
redirect URL : your relative subdirectory path e.g., if nopCommerce is installed in a subdirectory you would use /nopCommerce
redirect type : permanent
This will write to your web.config and add this section:
<system.webServer> <rewrite> <rules> <rule name="redirect" stopProcessing="true"> <match url="^$" /> <action type="RedirectToSubdir" url="/nopCommerce" /> </rule> </rules> </rewrite> </system.webServer>
That’s all there is to it.
Remember than any changes you make with IIS Manager are written to web.config, so overwriting web.config in the future can remove those changes.
Good article.
Also, it would be great to read some more detailed information about how to create a subdomain.
Thank you.
You will first need the subdomain add-on
https://my.discountasp.net/addons/unique-ip.aspx
some redirection or perhaps rewriting might get involved.
This might come out in next post. Stay tuned.
we want to install a wordpress blog and was told it needs to be a subdomain =http:// blog.ceceliasbestwishes.com – can we do a 301 redirect to resolve to:
ceceliasbestwishes.com/blog/
You can. Enable the subdomain add-on first from CP
https://my.discountasp.net/addons/unique-ip.aspx
There is a sample code on KB to do the redirection from your root to a subdirectory
If I just add that code directly to web.config does it matter where I put it (assuming I’m not breaking other code).
It does. Each tag nested on particular tag, as long as you follow the proper format you should be fine.
I am testing the site using discount asp Alternative url .is this suppose to work with alternative url because it is not?I don’t want to point to discounts asp nameserver until i am sure it works
i want my domain http://www.abc.com to point to http://www.abc.com/subdir1/subfolder1/abc.aspx
If you’re having problems you might want to post in the forum for some assistance. http://community.discountasp.net
Hello Tonny,
Thanks for the details. I have a question here. How would we redirect to https in case of subdirectory.
Example : xyz.com, http://www.xyz.com and http://www.xyz.com must be redirected to https://www.xyz.com under subdirecotory.
Regards,
Khalil
Thanks,
Works perfectly.