I have the catalog_category_default handle that has a content reference like this.
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
<!-- The following code shows how to set your own pager increments -->
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultListPerPage"><limit>10</limit></action>
<action method="setDefaultGridPerPage"><limit>9</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>10</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>20</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>30</limit></action>
<action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
<action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>30</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>60</limit></action>
<action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<!--action method="setColumnCount"><count>4</count></action-->
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
</reference>
I want to update it with the Layout Update from magento backend, to load a different template, so the line
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
should become
<block type="catalog/product_list" name="product_list" template="catalog/product/other-list.phtml">
I guess there's a better solution than remove content reference, and create a new one.
How can I update just that parameter?
In the layout update just add this:
<reference name="product_list">
<action method="setTemplate"><name>catalog/product/other-list.phtml</name></action>
</reference>
This is possible because Magento gives all it's blocks (and models and objects) magic setters.
Related
A website's file directory looks like the following:
In IIS. the website's directory is set to C:\mywebiste, and is bound port 8086. The following web page can be browsed without any problem:
https://localhost:8086/home/dist/
I want to use IIS rewrite to use the compressed foo.dat ONLY if it exists, so the web.config looks like the following:
<rule name="foo" stopProcessing="true">
<match url="foo.dat$"/>
<conditions>
<!-- Match brotli requests -->
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
<!-- Check if the pre-compressed file exists on the disk -->
<add input="{APPL_PHYSICAL_PATH}home\dist\_compressed_br\foo.dat" matchType="IsFile" negate="false" />
</conditions>
<action type="Rewrite" url="_compressed_br/foo.dat" />
</rule>
It works fine. Since I may distribute the contents under folder dist with the corresponding web.config in any directory, I am wondering if there is a parameter that can replace "{APPL_PHYSICAL_PATH}home\dist" so that I can use the same web.config no matter where I place them. This question is an extension from another similar question per the suggestion of the kind answer provider.
[Edit] 2019-10-03
Based on the excellent well commented answer, I can rewrite for all the files now:
<rule name="Rewrite br" stopProcessing="true">
<match url="^(.*)$"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<!-- Match brotli requests -->
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
<!-- following condition captures a group {C:1} with the value "C:\some\directory" for a path "c:\some\directory\foo.dat" -->
<!-- so we can use in the next condition to check whether the compressed version exists -->
<add input="{REQUEST_FILENAME}" pattern="^(.*)\\([^\\]*)$"/>
<!-- Check if the pre-compressed file exists on the disk -->
<!-- {C:1} used as requested file's parent folder -->
<add input="{C:1}\_compressed_br\{C:2}" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="_compressed_br/{C:2}" />
<serverVariables>
<set name="RESPONSE_Content-Encoding" value="br"/>
</serverVariables>
</rule>
If I understood you correctly, you always want to rewrite the version under the _compressed_br folder next to the web.config.
If so, give the following a try:
<rule name="foo" stopProcessing="true">
<match url="^foo\.dat$"/>
<!-- trackAllCaptures="true" is required to capture regex groups across conditions -->
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br"/>
<!-- following condition captures a group {C:1} with the value "C:\some\directory" for a path "c:\some\directory\foo.dat" -->
<!-- so we can use in the next condition to check whether the compressed version exists -->
<add input="{REQUEST_FILENAME}" pattern="^(.*)\\foo\.dat$"/>
<!-- {C:1} used as requested file's parent folder -->
<add input="{C:1}\_compressed_br\foo.dat" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="_compressed_br/foo.dat"/>
<serverVariables>
<set name="RESPONSE_Content-Encoding" value="br"/>
</serverVariables>
</rule>
I have a website that is served in two languages. I have a domain name for each language, e.g. www.englishsite.com and www.frenchsite.com
The application knows to change languages based on adding this URL parameter:
TemplateCulture=en-CA or TemplateCulture=fr-CA.
However, I am having little success with URL rewrite functionality in web.config to map the sub-domains to the specific language.
Below are the rules I am attempting to use. This isn't working for me, and I am hoping someone can point me in the right direction!
<rewrite>
<rules>
<rule name="redirect" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^http://www.englishsite.com$" />
</conditions>
<action type="Redirect" url="http://www.englishsite.com/?{R:0}TemplateCulture=en-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="redirect2" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^http://www.frenchsite.com$" />
</conditions>
<action type="Redirect" url="http://www.frenchsite.com/?{R:0}TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
If I understand correctly you are trying to achieve:
If user will visit homepage http://www.englishsite.com it should receive redirect to http://www.englishsite.com/?TemplateCulture=en-CA&{...something...}
If user will visit homepage http://www.frenchsite.com it should receive redirect to http://www.frenchsite.com/?TemplateCulture=fr-CA&{...something...}
Then you rules should be like that:
<rule name="redirect" enabled="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.englishsite.com$" />
</conditions>
<action type="Redirect" url="http://www.englishsite.com/?TemplateCulture=en-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="redirect2" enabled="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.frenchsite.com$" />
</conditions>
<action type="Redirect" url="http://www.frenchsite.com/?TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
Explanation of rules above:
<match url="^$" /> will match only for homepage
<add input="{HTTP_HOST}" pattern="^www.englishsite.com$" /> will create condition when domain name www.englishsite.com
<action type="Redirect" url="http://www.frenchsite.com/?TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" /> will make redirect with culture specific querystring. I removed {R:0} because IIS URL rewrite module will append it automatically because you set appendQueryString="true"
How can I redirect '/path?foo=abc&bar=def' to '/path/abc/def'?
I've tried the following:
<rule name="My rule" stopProcessing="false">
<match url="^path" />
<conditions>
<add input="{QUERY_STRING}" pattern="foo=/[^&]*/" />
<add input="{QUERY_STRING}" pattern="bar=(.*)" />
</conditions>
<action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>
But this doesn't even process my match. Where am I going wrong?
I don't have access to a computer to verify this, but I think the following could simplify:
<rule name="Redirect old FAQ view" stopProcessing="false">
<match url="^path.*" />
<conditions>
<add input="{QUERY_STRING}" pattern="^foo=([^&]*).*?bar=(.*)" />
</conditions>
<action type="Redirect" url="/path/{C:0}/{C:1}" appendQueryString="false" />
</rule>
You don't need the second input line as you can use multiple capturing groups in one. I'm not sure if the whole line will come back as a match or not so you may need to adjust to {C:1}/{C:2}. Finally, I'm not sure if the match url was problematic. It would contain the query string as well, so that may have been causing it to miss. Look here for more details on the various components of the URL rewrite process.
I want all request that look like:
(www.)mydomain.com/belgium(/*)
to be redirected to:
(www.)mydomain.be
The path and querystring after /belgium/ need to be included:
www.mydomain.com/belgium/page1/page11?filter=yes
Needs to become
www.mydomain.be/page1/page11?filter=yes
<rule name="Rewrite" enabled="true">
<match url="www.mydomain.com/belgium" />
<conditions logicalGrouping="MatchAll" >
<add input="{QUERY_STRING}" pattern="(.+)"/>
</conditions>
<action type="Redirect" url="www.mydomain.be?{C:1}" appendQueryString="true" />
</rule>
<rule name="Rewrite" enabled="true">
<match url="www.mydomain.com/belgium/{.*)" />
<action type="Redirect" url="www.mydomain.be{R:1}" appendQueryString="true" />
</rule>
You can write additional rule to handle www part of the link.
I write this out of my head so it is not correct but I believe it should give you a hint.
I Have some problems with redirecting to another URL based on the query string parameters. I want to redirect users which enter www.domain.com/signup.aspx?p=1 to:
www.domain.com/signup
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx\?p=1" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
Now when they enter www.domain.com/signup.aspx?p=2 they must go to:
www.domain.com/signup/promocode
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx\?p=2" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>
The above rules don't work. What is the right way to do this? Thanks in Advance.
Gr
Martijn
A more robust method of using a value to select a destination is to use Rewrite Maps. The map is essentially a lookup table. This doesn't require a new rule (and an additional evaluation of the URL against a pattern on every request) for every new path.
<rules>
<rule name="Signup Redirect Map" stopProcessing="true">
<match url="^signup\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="p=([^&]+)" />
<add input="{Signups:{C:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:2}" redirectType="Temporary" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="Signups">
<add key="1" value="signup" />
<add key="2" value="signup/promocode" />
<add key="3" value="signup/newcode" />
<add key="n" value="signup/futureproof" />
</rewriteMap>
</rewriteMaps>
Definitions:
{C:1} is a backreference to the first condition match: the query string value.
{Signups:{C:1}} is an instruction to look up {C:1} in the Signups map.
{C:2} is a backreference to the second condition match: the value from the Signups map.
See if this works a bit better:
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="p=1" />
</conditions>
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="p=2" />
</conditions>
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>