Access relative CSS/JS files with htaccess rewrite rule

后端 未结 2 406
遥遥无期
遥遥无期 2021-01-22 07:10

I was recently asked if I could make my friends server address more user friendly. His current urls looks like this:

http://wwww.example.com/site/index.php?page=         


        
2条回答
  •  猫巷女王i
    2021-01-22 07:19

    Better to use this rule:

    RewriteEngine On
    RewriteBase /site/
    
    RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]
    

    Then for css/js/images better to use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.

    Alternatively You can try adding this in your page's header:

    
    

    OR

    
    

提交回复
热议问题