asp.net - web.config redirection ignored on a shared hosting -


i have webpage hosted on shared microsoft-iis/8.5 server. don't have admin privileges on server, , don't have access configuration files, can't make sure url rewrite module or http redirect element correctly installed / set up.

i establish redirection folder named old_folder folder named new_folder (both @ root me, i.e., @ http://sharedhosting.com/myusername/). placed in root folder following web.config file:

<?xml version="1.0" encoding="utf-8"?>  <configuration>     <configsections>         <sectiongroup name="system.webserver">             <sectiongroup name="rewrite">                 <section name="rules" overridemodedefault="allow" />             </sectiongroup>         </sectiongroup>     </configsections>      <system.webserver>         <rewrite>             <rules>                 <rule name="attempt" stopprocessing="true" enabled="true">                 <match url="^old_folder/$" />                 <action type="redirect" url="new_folder/" redirecttype="permanent"/>                 </rule>             </rules>         </rewrite>     </system.webserver> </configuration> 

but can 403 - forbidden: access denied. (if leave empty old_folder) or 404 - file or directory not found. (if erase it).

i tried using http redirect, placing in old_folder web.config file containing

<?xml version="1.0" encoding="utf-8"?> <configuration>     <system.webserver>         <httpredirect enabled="true" destination="http://sharedhosting.com/myusername/new_folder/" />     </system.webserver> </configuration>  

but didn't worked either.

i know web.config files read (i can 500 errors if there error in them). suspect url rewrite installed, since, instance, http://sharedhosting.com/myusername/folder rewritten http://sharedhosting.com/myusername/folder/ (i.e., slash) if folder folder exists.

is rule correct? host prevent me redirecting? if yes, how can tell?

i added <clear /> after <rules> tag discard other rewriting rules, still isn't redirecting anything.

what missing?


edit

following webruster's answer, tried following (adaptation of his) web.config:

<?xml version="1.0" encoding="utf-8"?>  <configuration>     <configsections>         <sectiongroup name="system.webserver">             <sectiongroup name="rewrite">                 <section name="rewritemaps" overridemodedefault="allow" />                 <section name="rules" overridemodedefault="allow" />             </sectiongroup>         </sectiongroup>     </configsections>      <system.webserver>         <rewrite>              <rewritemaps>                 <rewritemap name="yourredirects">                     <add key="/old_folder/" value="/new_folder/" />                 </rewritemap>             </rewritemaps>              <rules>                 <rule name="attempt" stopprocessing="true" >                     <match url=".*" />                     <conditions>                         <add input="{yourredirects:{request_uri}}" pattern="(.+)" />                     </conditions>                     <action type="redirect" url="http://sharedhosting>com/myusername/{c:1}" appendquerystring="false" redirecttype="permanent" />                 </rule>             </rules>          </rewrite>     </system.webserver>  </configuration> 

note without part between <configsections>, had 500 error. it, don't 500 error, redirection isn't happening either.

i'm not sure know how set solution httphandlers suggested. attempts failed far.

edit 2 we came conclusion server weirdly set-up , there wasn't do. if have suggestion contradict conclusion, feel free add answer ;-)

you can achieve same thing using httphandlers , i'm presuming can access both old_folder , new_folder directly in browser .

here sample httphandlers , can in way :

youname.handlers {    public class redirecthandler : ihttphandler   {       public void processrequest(httpcontext context)      {         context.response.status = "301 moved permanently";         string url = context.request.url.tostring().replace("old_folder", "new_folder");         context.response.addheader("location", url);       }       public bool isreusable      {         { return false; }      }     } } 

in web_config add handler follows:

system.web>    <httphandlers>      <add verb="*" path="xxx/*.*" type="yourname.handlers.redirecthandler"/>    </httphandlers> </system.web> 

using iis url_rewriting :

   <?xml version="1.0"?> <configuration>     <system.webserver>         <rewrite>             <rewritemaps>                 <rewritemap name="yourredirects">                     <add key="/yourroot/old_folder/" value="/otherdir/new_folder" />                 </rewritemap>             </rewritemaps>             <rules>                 <rule name="redirectrule" stopprocessing="true">                     <match url=".*" />                     <conditions>                         <add input="{yourredirects:{request_uri}}" pattern="(.+)" />                     </conditions>                     <action type="redirect" url="http://www.yourdomain.com{c:1}" appendquerystring="false" redirecttype="permanent" />                 </rule>             </rules>         </rewrite>     </system.webserver> </configuration> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -