How to redirect url
from
www.example.com/file.html
to
www.example.com/folder/file.html
using .htaccess and web.config
I have been searching for hours and have found several topics but none works for us
For IIS:
Open web.config in the directory where the old page resides. Then add code in web.config there for the old location path and new destination as follows:
<configuration>
<location path="file.html">
<system.webServer>
<httpRedirect enabled="true" destination="www.example.com/folder/file.html" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
For apache:
Add in .htaccess the following line:
Redirect /file.html http://example.com/folder/file.html
Related
I have followed the instruction reported here :
https://www.c-sharpcorner.com/UploadFile/francissvk/set-default-page-for-a-website-in-iis421/
What i would like to achieve, is that when user try to visit my site : "https://mysitename.com" it should be redirected to the home page ( "https://mysitename.com/pages/home.aspx").
I don't want to create a root Default.aspx page only to do the redirect, i would like to achieve this behaviour through Web.config.
As said, i tried the instruction in the above link, buy also tried the many solution proposed on this site that more or less suggest to add this configuration to Web.config :
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="/Pages/Home.aspx"/>
</files>
</defaultDocument>
<handlers>
I have tried different variation of the path, i have tried :
<add value="/Pages/Home.aspx"/>
<add value="~/Pages/Home.aspx"/>
<add value="./Pages/Home.aspx"/>
<add value="Home.aspx"/>
But allways i get this message error :
403 - Access denied.
If i manually enter in the browser the full page url "https://mysitename.com/pages/home.aspx" then i get no issue (just to point out that the page exists and is working)
I don't understand what i am missing in the configuration
A default page or DefaultDocument in IIS can't do what you want.
It is a feature that defines which document is loaded when a user requested a URL pointing to a directory on the server without specifying an actual page.
The value field should be the name of a file in that directory such as index.html or home.asp, it can not point to files in other directories.
In your case you may be able to use the builtin HTTP Redirect feature, in the GUI enable it and point to 'pages', also check the Only redirect requests to... checkbox
In your root web.config this may look like this:
<system.webServer>
<httpRedirect enabled="true" destination="pages" childOnly="true" />
<defaultDocument enabled="true">
<files>
<clear />
<add value="Home.aspx"/>
</files>
</defaultDocument>
</system.webServer>
Another option is to use the IIS Rewrite Module which allows you to create more complex rules on how to redirect and rewrite requests. It should be faster because it does work without a HTTP redirect which does back to the browser, but you first need it install it and understand how to use it.
My IIS setup has one site, bound to a domain. Let's call it: www.mydomain.com
The site folder itself is empty. This site hosts multiple applications and virtual directories. One of the applications is 'portal'.
What I want to do is accept any incoming request for www.mydomain.com or www.mydomain.com/ and redirect it to: www.mydomain.com/portal
I've got ARR and URL Rewrites up and running. I'm just not sure how to configure them for this.
A redirection rule like below will work.
Put the following web.config file to your web site's root folder. Or, update the existing one if you have.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="toPortal" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/portal" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You may want look at this tutorial to learn how to create url rewrite rules with IIS Manager. These xml nodes are not coming from my brain too.
I am want to redirect a url to another url by using IIS redirect. But i need to know how can i achieve this by using IIS redirect and also i need regular expression which redirect a specific URL to another url.
this is the Url which user will hit.
http://myurl.com/blog/social-media-page/
now i need to redirect above url to this url
http://blog.myurl.com/social-media-page/
how can i achieve this by using IIS redirect. I need to do this immediately.
For IIS 7+ update web.config of myurl.com to have following redirect
<?xml version="1.0"?>
<configuration>
<configSections>
..
</configSections>
<location path="social-media-page">
<system.webServer>
<httpRedirect enabled="true" destination="http://blog.myurl.com/social-media-page/" httpResponseStatus="Permanent" childOnly="true" />
</system.webServer>
</location>
I tested it and it works fine. All whats come to myurl.com/social-media-page is redirected (permanent redirect) to blog.myurl.com/social-media-page.
I have a .net site on a shared host environment so I don't have access to other solutions that require access to the server.
If I put the following code in my current web.config, is it enough to do the 301 redirect to my-new-site.com? Thanks.
<system.webServer>
<httpRedirect enabled="true" destination="http://www.my-new-site.com/" />
</system.webServer>
HTTP Redirection is not available on the default installation of IIS 7. You have to add it in Common Http Features for the Web Server Role. Is it enabled on your shared host ?
The correct way to do a permanent 301 redirect is :
<system.webServer>
<httpRedirect enabled="true" destination="http://www.my-new-site.com/" httpResponseStatus="Permanent" />
</system.webServer>
the default is response status is 302 (Found). More infos here.
We'd like to use IIS 7.5 output caching for an individual .aspx file, but after some reading at iis.net, it seems to me the caching can only be configured for various file extensions, but not for individual files. Is that correct or did I miss something?
Thank you.
Just change view to "content" select file, and config it. In extension add eq .js or .php. This config will be only to this file.
You can check this in:
eq
web.config
<location path="cachedfile.php">
<system.webServer>
<caching>
<profiles>
<add extension=".php" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="00:30:00" />
</profiles>
</caching>
</system.webServer>
</location>