URL Rewriing Using Intelligencia.UrlRewriter

Hi There

I am using Intelligencia.UrlRewriter to rewrite my urls.

My problem is that if I rewrite my urls my image paths and links within the page all adopt the new formated url path.

I am using a database lookup to replace the url like so.

  string urlPath = Context.Request.Path.ToString().TrimStart('/');
        string replacement = "";

        Toyota.CMS.Web.App_Files.FriendlyURLManager manager = new Toyota.CMS.Web.App_Files.FriendlyURLManager();
        replacement = manager.MapFriendlyURL(urlPath.ToLower());
       
     
        if (!String.IsNullOrEmpty(replacement))
        {
            Context.RewritePath(replacement);

            if (!string.IsNullOrEmpty(Request.QueryString["Test"]))
            {
                Context.RewritePath("~/VehicleRangeChoose.aspx");
            }
            else
            {
                urlPath = urlPath.Replace(urlPath, replacement);
                Context.RewritePath(urlPath);

            }

        }
The url rewriting works fine but it makes my images and styles display incorrectly.

www.mysite.co.za/products/product_1
Correctly maps to www.mysite.co.za/products.aspx?ProductId=1

But all my image paths and links change from
www.mysite.co.za/images/products/product_1/image1.jpg
but they should be
www.mysite.co.za/images/image1.jpg

Is there a way to handle these without having to change the entire page.

I have done something like this in the webconfig but it does not seem to be working correctly.

 <rewrite url="/App_Themes/(.+)" to="~/App_Themes/$1" />
    <rewrite url="/images/icons/(.+)" to="~/images/icons/$1" />
   
    <rewrite url=".*/PictureData/(.+)" to="~/PictureData/$1" />
      <rewrite url=".*/PictureData/.*" to="~/PictureData/$1" />
    <rewrite url=".*/models/includes/(.+)" to="~/includes/$1" />-->
     <rewrite url=".*/models/PictureData/(.+)" to="~/PictureData/$1" />

Basically I want to remove the products/product_1 from all other urls in the page.







Stanton_RouxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
ideally you should be checking for .aspx extension before acting

if (Request.Url.AbsoluteUri.ToLower().Contains(".aspx"))
{
// do rewriting logic here , so that all images and css will not be filtered
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stanton_RouxAuthor Commented:
I am only rewriting the URL if it has a match in the database.

I am not sure at which point the rest of the replacements are made.
0
masterpassCommented:
Try some thing like this

if (Request.Url.AbsoluteUri.ToLower().Contains(".aspx"))
{
Toyota.CMS.Web.App_Files.FriendlyURLManager manager = new Toyota.CMS.Web.App_Files.FriendlyURLManager();
        replacement = manager.MapFriendlyURL(urlPath.ToLower());
       
     
        if (!String.IsNullOrEmpty(replacement))
        {
            Context.RewritePath(replacement);

            if (!string.IsNullOrEmpty(Request.QueryString["Test"]))
            {
                Context.RewritePath("~/VehicleRangeChoose.aspx");
            }
            else
            {
                urlPath = urlPath.Replace(urlPath, replacement);
                Context.RewritePath(urlPath);

            }

        }
}
0
Stanton_RouxAuthor Commented:
Yeah that wont work.

As I am not passing the aspx page into that function.
I am passing the friendly url that does not have an extension.
and rewriting it as the .aspx page.

But the friendly url is the one displayed in the navigation window
0
masterpassCommented:
before giving a friendly url to that function have this check .. means to check before you convert the actual url to friendly url so that images and css are not filtered
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Miscellaneous

From novice to tech pro — start learning today.