URL rewrite issue not loading .css

孤人 提交于 2019-12-02 08:39:50

问题


I'm porting an old site to a new template and am having problems with the Windows 2008 rewrite module. The link I'm trying to rewrite looks like this:

http://ltweb2008.serveronline.net/product.php?pID=75

and brings up the page just fine. Then I apply the new URL and it loads the proper content, but doesn't load the template's style.css file anymore.

http://ltweb2008.serveronline.net/product/75/any-text-here

The problem seems to be that the company who made the template (canvas) put the main .css file in the root directory, but loaded all the rest in /css. Now I can't get the main .css file to load using the rewrite and when I move it down to /css it only displays a blank page, though when I check out the page source it's all there.

With this the page shows but is not using style.css (with rewrite):

<link rel="stylesheet" href="style.css" type="text/css" />

With any of these the page is completely blank (with rewrite):

  1. <link rel="stylesheet" href="/style.css" type="text/css" /> OR
  2. <link rel="stylesheet" href="/css/style.css" type="text/css" /> OR
  3. <link rel="stylesheet" href="http://ltweb2008.serveronline.net/style.css" type="text/css" />

I'm using this for the Pattern:

^product/([0-9]+)/([^/]+)$

And the Rewrite URL:

/product.php?pID={R:1}

Does anyone know what I'm missing?


回答1:


one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files,

This is because your relative URIs have their base changed. Originally, the base is / when the page is /product.php?id=75, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /product/75/any-text-here the base suddenly becomes /product/ and it tries to append that in front of all relative URLs and thus none of them load.

You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):

<base href="/">



回答2:


Maybe you need one thing, maybe both, I didn't test, but this solved it for me:

1.) ADD THIS in page_load :

Page.Header.DataBind() ' Needed because we have <%# %> codeblocks in the HEADER (seems header only causing this) WITH the AjaxControlToolkit running on the page. That's what broke it until we put in this and put in the pound instead of = sign in the html.

2.) Add this in ASPX:

<%@ MasterType VirtualPath="~/dir1/dir2whateverdir/MasterPage.master" %>



来源:https://stackoverflow.com/questions/34983870/url-rewrite-issue-not-loading-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!