How do I exclude CSS, JS, JPG, GIF files from mod_rewrite rules?

前端 未结 4 1134
挽巷
挽巷 2021-01-14 06:26

This is what I have so far:

RewriteRule ^([A-Za-z0-9_]*)/?$ index.php?page=$1 [NC]
RewriteRule ^([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ index.php?page=$1/$2 [NC]
         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 07:02

    The problem that you are experiencing is not that the mod_rewrite is being applied to css files, but rather that the paths in your html to your css is relative. The browser is simply requesting the css from the correct relative path. You really have two options.

    1. Make your paths to your css relative to the domain instead of to the page (e.g. use /ssi/styles.css instead of ssi/styles.css)
    2. Create a rewrite rule to redirect all css to the correct URL. (e.g. RewriteRule (*.css) /ssi/$1

提交回复
热议问题