开发者

.htaccess file on xampp (basedir wrong.. incorrect path for images, css files..)

开发者 https://www.devze.com 2023-03-13 12:57 出处:网络
i got another problem. i have an own apache server (XAMPP) on my computer. The URL in my browser looks like

i got another problem.

i have an own apache server (XAMPP) on my computer. The URL in my browser looks like

http://localhost/pageExample/index.php

i use a .htaccess file to change my url from ?action=home to home.html

The problem now is, that the path to all images, css files etc be wrong. They looks like

http://localhost/images/logo.jpg

I think, there is something wrong 开发者_JAVA百科in my .htaccess file... i tried <base href="http://'.$_SERVER['HTTP_HOST'].'/pageExample/">.. this works ..okay... but some scripts with extern images doesnt work.

My .htaccess file looks like:

RewriteEngine On
RewriteRule ^home.html$ /pageExample/index.php?action=home [L]

(By the way... the problem came since I created the .htaccess)

How to change this? Thanks!


This is a common problem when you start rewriting URLs but website is not coded accordingly. In your HTML/CSS, when you are referring to images/scripts/css resources you most likely have something like this: <img src="images/hello.jpg" />. Bacuse you are rewriting URLs you need to alter the resource URLs as well -- in the above example resource is linked to the path of the HTML file (relative path) -- you need to make the path absolute. For this -- add leading slash before resource references:

change

<img src="images/hello.jpg" />

to

<img src="/images/hello.jpg" />

0

精彩评论

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