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

前端 未结 4 1090
挽巷
挽巷 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 06:57

    Anticipating you're using Apache with mod_rewrite module, you should try the RewriteCond Directive. The following example excludes all the matches from RewriteCond for the following line with the RewriteRule Directive. The rules are basically regular expression. The one in my example excludes everything which starts with either favicon.ico as well as with css, which is the folder, where my Stylesheets resides.

    RewriteEngine On
    RewriteCond $1 !^(favicon\.ico|favicon\.png|media|robots\.txt|crossdomain\.xml|css|js)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    Further reading: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

提交回复
热议问题