CSS, JS and images do not display with pretty url

后端 未结 4 1601
猫巷女王i
猫巷女王i 2020-11-27 23:18

I am trying to rewrite the URL through the htaccess file so that the following URL

www.domain.com/subfolder/index.php?key

can be accessed b

4条回答
  •  攒了一身酷
    2020-11-28 00:07

    Actually there is a solution with .htaccess !

    Assuming that your index.php is located in /mysite/ and your ressources files are in /mysite/scripts/, /mysite/images/ and/mysite/style/ like mines, you could go like this :

    RewriteEngine on
    #first exclude those folders
    RewriteBase "/mysite/"
    RewriteRule ^(style|scripts|images)($|/) - [L]
    #then go with your rules (the [L] terminates the ruling)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{DOCUMENT_ROOT}/$1 -f
    RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]
    RewriteRule ^index.php/([a-zA-Z0-9/_]+)$ index.php?key=$1
    

    You can see .htaccess mod_rewrite - how to exclude directory from rewrite rule for few other ways

提交回复
热议问题