CSS not loading after redirect with htaccess rewrite rule

前端 未结 12 2216
自闭症患者
自闭症患者 2020-12-03 05:18

I have the following Short-hand for a user profile url

RewriteRule ^(\\w+)/?$ ./profile.php?name_of_user=$1

The site is styled with the app

相关标签:
12条回答
  • 2020-12-03 06:09

    Simply add the base path after the opening head tag. For example:

    <base href="website url here">
    
    0 讨论(0)
  • 2020-12-03 06:11

    I've had what seems to be the same problem. I was trying to redirect from a site of the form: www.foo/category/details.

    I found the slash after "category" stopped both the CSS and images from being loaded.

    The cause is the default redirection passes the original URL to the browser. This can be seen from a JScript trace on window.location.pathname. The solution is simply to use a [R] flag in the rewrite rule.

    0 讨论(0)
  • 2020-12-03 06:12
    RewriteCond %{REQUEST_FILENAME} !-f
    

    This works like a treat. I originally had problem even with giving absolute linking. Thanks and +1 to Steve Lewis.

    0 讨论(0)
  • 2020-12-03 06:13

    link the css files relative to the root directory sample:

    <link rel="stylesheet" type="text/css" href="/css/****.css">
    
    0 讨论(0)
  • 2020-12-03 06:14

    I had this same problem and have found the easiest and most practical solution.

    <base href="http://www.example.com/" />
    

    It's super clean and easy to use.

    0 讨论(0)
  • 2020-12-03 06:14

    When you use this site.com/name_of_user/ you change the working directory on your site from root to name_of_user, therefore the relative path for each file or link on the requested page would become /name_of_user/ instead of /.

    To fix this you need to add additional rule to .htaccess:

    RewriteRule ^name_of_user/(.*)?$ $1
    
    0 讨论(0)
提交回复
热议问题