Css, image, and js do not work in the .htaccess file
source link: https://www.codesd.com/item/css-image-and-js-do-not-work-in-the-htaccess-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Css, image, and js do not work in the .htaccess file
my code is below , and my code is not able to fetch all css, js and images which is located in diffrent folders
RewriteEngine On
RewriteBase /
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [NC] [OR]
RewriteCond %{THE_REQUEST} \s/+product\.php\.css\?id=([^\s&]+) [NC]
RewriteRule ^ product/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^product/([^/.]+)/?$ product.php?id=$1 [L,QSA]
RewriteRule ^([A-Za-z\s0-9-]+)/?$ /product.php?id=$1 [L,QSA]
Your problem is that, your relative URIs have their base changed. Originally, the base is /
when the page is /product.php
, and the browser properly fills in relative links with the /
base. But when the browser goes to a page like /product/
the base suddenly becomes /product/
and it tries to append that in front of all relative URLs and thus none of them load.
You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head>
tags):
<base href="/">
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK