开发者

.htaccess redirect causes css nor images to load

开发者 https://www.devze.com 2023-03-03 12:31 出处:网络
I have the following .htaccess to force all files to go through a index.php file and I just 开发者_JS百科noticed that all my references to the css, javascript, images, stop working. I think is the hta

I have the following .htaccess to force all files to go through a index.php file and I just 开发者_JS百科noticed that all my references to the css, javascript, images, stop working. I think is the htaccess that is causing this, if so, how can I solve this?

Here is my .htaccess file:

<IfModule mod_rewrite.c>

# redirect all calls to index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>


The typical cause is that your HTML templates contain relative links to your resources.

<link rel="stylesheet" type="text/css" href="main.css">

Will fail as soon as your pages no longer reside under /index.html but in /app/index. You now have a new virtual directory in your URL, hencewhy the CSS and images are assumed to be located under /app/ too if you didn't specify absolute path names /img/logo.png everywhere.

A classic workaround is to add this in your template <head>:

<base href="/">

This will force browsers to prepend the / (in this example) to all relative resource links.

0

精彩评论

暂无评论...
验证码 换一张
取 消