Evening,
I’ve been tasked with moving a website from subdomain.domain.com to domain.com/subdomain.
Issues I have:
Both the original subdomain and and the domain name have url rewriting rules (asp.net, UrlReWriter)
So, I’ve moved (or rather, copied) the subdomain content files to the new subfolder under the main domain and things seem to be going really well but having one or two issues…
I need to match the following:
http://www.maindomain.com/category.aspx?name=foo -> http://www.maindomain.com/foo/
http://www.maindomain.com/viewproduct.aspx?catName=foo&productName=bar -> http://www.maindomains.com/foo/bar.aspx
I kind have already got that bit working but, because of config file inheritance, i have to specify the rewrite rules in the main application (main domains) web.config so I need to also match these rules:
http://www.maindomain.com/us/category.aspx?name=foo -> http://www.maindomain.com/us/foo/
http://www.maindomain.com/us/viewproduct.aspx?catName=foo&productName=bar -> http://www.maindomain.com/us/foo/bar.aspx
Obviously, the rewrite engine needs to ignore css/images other files etc, including for example:
http://www.maindomain.com/about.aspx & http://www.maindomain.com/us/about.aspx
Need any other info, just ask..
The rules I have at the moment are:
<rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$" to="$1" processing="stop"/>
<rewrite url="^/us/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?$" to="$1" processing="stop"/>
<rewrite url="^/us/Error.aspx" to="$1" processing="stop"/>
<rewrite url="^/us/Error404.aspx" to="$1" processing="stop"/>
<rewrite url="Error.aspx" to="$1" processing="stop"/>
<rewrite url="Error404.aspx" to="$1" processing="stop"/>
<rewrite url="^/us/$" to="$1" processing="stop"/>
<rewrite url="^/us/(.+)/(.+).aspx" to="/us/viewProduct.aspx?productName=$2&catName=$1" processing="stop"/>
<rewrite url="^/us/(.+)/" to="/us/category.aspx?name=$1" processing="stop"/>
<rewrite url="^/(.+)/(.+).aspx" to="~/viewProduct.aspx?productName=$2&catName=$1" processing="stop"/>
<rewrite url="^/(.+)/" to="~/category.aspx?name=$1" processing="stop"/>
Using, iis7.5, c#, asp.net v2
Thanks
Michael
There’s a few issues here. The first is that the following rewrite rule can’t work:
You’re asking the rewrite module to replace the url
/us/with match group one, but you don’t have a group in your capture expression. To fix this, and to deal with .aspx files in tha/us/folder, replace it with the following two rules:In addition, your second rewrite rule (for static content in the
/us/folder) isn’t needed, because the first rewrite rule doesn’t care what folder the file is in, and will match (and stop processing) for urls such as/us/images/foo.jpg.