Simple url rewrite

Posted: September 02, 2016 at 8:06 PM Quote #174651
I have been using my forum to post recipes that customers can use with my products.  I'd like to publish the location of this forum in a simple url on my brochures, labels, etc.  So how can I do a simple rewrite somewhere in the app?  I'd like people to be able to type www.anarchyacres.com/recipes into their browser and get to my recipe forum at http://www.anarchyacres.com/boards/forum/4/recipes.

I've tried url rewrite in IIS but I'm too dumb to make it work.  Maybe the rewrite should be in the application somewhere, preferably something easy like the .config file or global.asax.  I don't really care if it's a redirect or a rewrite, I just want people to easily find the forum topic.

Thanks for a great product!  MVC has been a steep learning curve for me but I love the application and hope to keep customizing my site.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Charlie
Posted: September 04, 2016 at 2:38 PM Quote #174712
[email protected] wrote:
I have been using my forum to post recipes that customers can use with my products.  I'd like to publish the location of this forum in a simple url on my brochures, labels, etc.  So how can I do a simple rewrite somewhere in the app?  I'd like people to be able to type www.anarchyacres.com/recipes into their browser and get to my recipe forum at http://www.anarchyacres.com/boards/forum/4/recipes.

I've tried url rewrite in IIS but I'm too dumb to make it work.  Maybe the rewrite should be in the application somewhere, preferably something easy like the .config file or global.asax.  I don't really care if it's a redirect or a rewrite, I just want people to easily find the forum topic.

Thanks for a great product!  MVC has been a steep learning curve for me but I love the application and hope to keep customizing my site.


You can just create a static rewrites file and upload to your website..it is a little tricky, but free.
In your web.config, you'll add a reference to a rewriteMap like this:

<system.webServer>
    <rewrite>
      <rewriteMaps configSource="StaticRedirects.config" />
      <rules>
        <rule name="non-www to www" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="Rewrites Redirect Rule">
          <match url=".*" />
          <conditions>
            <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>


That StaticRedirects.config file will be structured something like this:
The "key" is the old address and the "value" is the new address.

<rewriteMaps>
       <rewriteMap name="StaticRedirects" defaultValue="">
           <add key="/detail.asp?ProductID=948" value="/3pp-arch-lift" />
           <add key="/detail.asp?ProductID=830" value="/3pp-plantar-fasciitis-lift" />
           <add key="/detail.asp?ProductID=864" value="/3pp-toe-loops" />
           <add key="/detail.asp?ProductID=873" value="/achilles-tendon-support-by-pro-tec" />
           <add key="/detail.asp?ProductID=856" value="/airheel-by-aircast-2" />
           <add key="/detail.asp?ProductID=858" value="/malleoloc-ankle-brace" />
           <add key="/detail.asp?ProductID=789" value="/ankle-support-elastic-1" />
</rewriteMap>
</rewriteMaps>



You just need to create an entry for each of your old addresses so as to inform the search engines about the permanent redirects to new addresses.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
An upvote on a helpful post means "thank you" in every language. I believe in this community. For every question I ask, I try to answer at least five others.
Posted: September 04, 2016 at 8:50 PM Quote #174721
Thanks!  That did the trick.  For future guidance, here is the full text of StaticRedirects.config that ended up working for me:

<?xml version="1.0"?>
  <rewriteMaps>
    <rewriteMap name="StaticRedirects" defaultValue="">
      <add key="/recipes" value="/boards/forum/4/recipes" />
    </rewriteMap>
  </rewriteMaps>

Kind of tricky to get it just right--got a lot of 404's and then I discovered that chrome actually memorizes the redirect, so changing the rewrite map afterwards may not be possible if users have already used the redirect.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Charlie
Posted: February 20, 2018 at 3:36 PM Quote #200956
embryo wrote:
I have been using my forum to post recipes that customers can use with my products.  I'd like to publish the location of this forum in a simple url on my brochures, labels, etc.  So how can I do a simple rewrite somewhere in the app?  I'd like people to be able to type www.anarchyacres.com/recipes into their browser and get to my recipe forum at http://www.anarchyacres.com/boards/forum/4/recipes.

I've tried url rewrite in IIS but I'm too dumb to make it work.  Maybe the rewrite should be in the application somewhere, preferably something easy like the .config file or global.asax.  I don't really care if it's a redirect or a rewrite, I just want people to easily find the forum topic.

Thanks for a great product!  MVC has been a steep learning curve for me but I love the application and hope to keep customizing my site.

You can just create a static rewrites file and upload to your website..it is a little tricky, but free.
In your web.config, you'll add a reference to a rewriteMap like this:

<system.webServer>
    <rewrite>
      <rewriteMaps configSource="StaticRedirects.config" />
      <rules>
        <rule name="non-www to www" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="Rewrites Redirect Rule">
          <match url=".*" />
          <conditions>
            <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>


That StaticRedirects.config file will be structured something like this:
The "key" is the old address and the "value" is the new address.

<rewriteMaps>
       <rewriteMap name="StaticRedirects" defaultValue="">
           <add key="/detail.asp?ProductID=948" value="/3pp-arch-lift" />
           <add key="/detail.asp?ProductID=830" value="/3pp-plantar-fasciitis-lift" />
           <add key="/detail.asp?ProductID=864" value="/3pp-toe-loops" />
           <add key="/detail.asp?ProductID=873" value="/achilles-tendon-support-by-pro-tec" />
           <add key="/detail.asp?ProductID=856" value="/airheel-by-aircast-2" />
           <add key="/detail.asp?ProductID=858" value="/malleoloc-ankle-brace" />
           <add key="/detail.asp?ProductID=789" value="/ankle-support-elastic-1" />
</rewriteMap>
</rewriteMaps>



You just need to create an entry for each of your old addresses so as to inform the search engines about the permanent redirects to new addresses.





I read the report. But my file is bigger than 250KB.

Do you have an example for me how I can solve my problem.

NopCommerce Version 4.00 and 3.90
Windows Server 2016
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
https://www.tonerkauf24.de
Posted: February 20, 2018 at 4:41 PM Quote #200958
Maximum size of a web.config allowed is 250KB by default. You can change regkey HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB to allow bigger web.config if needed.

As described in my initial post, you can get around that by creating a separate redirect file so that your web.config filesize is not affected.

<system.webServer>
    <rewrite>
      <rewriteMaps configSource="StaticRedirects.config" />
      <rules>
        <rule name="non-www to www" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="Rewrites Redirect Rule">
          <match url=".*" />
          <conditions>
            <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>


And the StaticRedirects.config file will map all your new URLs:

<?xml version="1.0"?>
  <rewriteMaps>
    <rewriteMap name="StaticRedirects" defaultValue="">
      <add key="/recipes" value="/boards/forum/4/recipes" />
      <add key="/aboutus" value="/about" />
    </rewriteMap>
  </rewriteMaps>



Read more here:
http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
An upvote on a helpful post means "thank you" in every language. I believe in this community. For every question I ask, I try to answer at least five others.
Posted: February 21, 2018 at 4:08 AM Quote #200975
embryo wrote:
Maximum size of a web.config allowed is 250KB by default. You can change regkey HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB to allow bigger web.config if needed.

As described in my initial post, you can get around that by creating a separate redirect file so that your web.config filesize is not affected.

<system.webServer>
    <rewrite>
      <rewriteMaps configSource="StaticRedirects.config" />
      <rules>
        <rule name="non-www to www" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
        </rule>
        <rule name="Rewrites Redirect Rule">
          <match url=".*" />
          <conditions>
            <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>


And the StaticRedirects.config file will map all your new URLs:

<?xml version="1.0"?>
  <rewriteMaps>
    <rewriteMap name="StaticRedirects" defaultValue="">
      <add key="/recipes" value="/boards/forum/4/recipes" />
      <add key="/aboutus" value="/about" />
    </rewriteMap>
  </rewriteMaps>



Read more here:
http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/



Thanks for the answer.

Under Windows Server 2016, there is only "SOFTWARE\Microsoft\InetStp\Components" but not "SOFTWARE\Microsoft\InetStp\Configuration". Does "SOFTWARE\Microsoft\InetStp\Components" need to be created?
Does the decimal value have to be entered in kb?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
https://www.tonerkauf24.de
Posted: February 21, 2018 at 4:44 AM Quote #200978
I did that. It does not work with Windows Server 2016 64bit.

the value is newly created: Configuration\MaxWebConfigFileSizeInKB and REG_DWORD(1024)


HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD)
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
https://www.tonerkauf24.de
Posted: July 25, 2018 at 7:44 AM Quote #209339
Hi,

I have just tried to do this for 4.0 but it throws an error. Do I need to do it differently for 4.0, or am I just doing something wrong?

Thanks
Neil
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 15, 2019 at 4:36 PM Quote #227539
If you have a large number of URLs, I strongly recommend using FileMapProvider instead using rewriteMaps.  It allows you to have a large file full of URLS without the XML formatting requirement.  Simply create a {DOCUMENT_ROOT}\App_Data\OldUrlsRedirectMappings.txt file and add entries:

/old_url/product_1    /new_url/product-1


You also have an option for setting the delimiter, in the example it's just whitespace.

It requires an IIS module installation.  Make sure you install the module and restart IIS to ensure it is properly loaded.  Also, make sure your urls paths start with a '/', otherwise they won't be matched.  I discovered this the hard way.  Finally, make sure you have .NET 4 along with integrated pipeline or you'll get a 500 server error.

The following has installation instructions and where you can download the module:
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-custom-rewrite-providers-with-url-rewrite-module

The following Rewrite

    <rewrite>
      <rules>
        <clear />
        <rule name="RemapOldUrls" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
                        <add input="{FileMap:{R:1}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="false" />
        </rule>
      </rules>
      <providers>
        <provider name="FileMap" type="FileMapProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f">
          <settings>
            <add key="FilePath" value="{DOCUMENT_ROOT}\App_Data\OldUrlsRedirectMappings.txt" />
            <add key="IgnoreCase" value="1" />
          </settings>
        </provider>
      </providers>
    </rewrite>
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.