I must do a redirect using a regex...
I must do the following redirects:
www.mysite.com/old-category/old-subcategory -> www.mysite.com/new-category/new-subcategory
www.mysite.com/old-category/old-subcategory/old-page1 -> www.mysite.com/new-category/new-subcategory/new-page1
www.mysite.com/old-category/old-subcategory/old-page2 -> www.mysite.com/new-category/new-subcategory/new-page2
...
www.mysite.com/old-category/old-subcategory/old-pageN -> www.mysite.com/new-category/new-subcategory/new-pageN
where new-pageN
can be a randow word...
Here my rule in the web.config:
<rewrite>
<rules>
...
<rule name="myCustomRule">
<match url="^old-category/old-subcategory/(.*)" ignoreCase="false" />
<action type="Redirect" url="new-category/new-subcategory/{R:1}" />
</rule>
</rules>
</rewrite>
The problem is that when I write www.mysite.com/old-category/old-subcategory/old-page1
in my browser, It is redirect to www.mysite.com/new-category/new-subcategory/n
. It takes just the first letter of the last segment of the old url.
I do not understand what is wrong... everything look like correct to me.. I have also tried with
^old-category/old-subcategory/(.+)
^old-category/old-subcategory/(\w+)
^old-category/old-subcategory/([0-9a-zA-Z_]+)
^old-category/old-subcategory/(\b\w+\b)
Nothing works... What's wrong?
Thank you
Your question is not much clear... By the way
Try to escape the "/" <match url="^old-category\\/old-subcategory\\/(.*)"
ignoreCase="false" />
I think that redirect should be:
<action type="Redirect" url="/new-category/new-subcategory/{R:1}" />
or
<action type="Redirect" url="http://www.example.com/new-category/new-subcategory/{R:1}" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.