3

Im doing a website with only one page and I want do put in url like: "http://test.com/portfolio" and my htaccess to access the same page like http://test.com/#portfolio, I already get this with the code below, but when I put http://test.com/portfolio/, with '/' after, the server open the same page, but without css, links with images... The browser show only the html code.

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine On

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d

    RewriteRule ^portfolio(.*)$ #portfolio
    RewriteRule ^contact(.*)$ #contact

</IfModule>

You know something to help me?

4

1 回答 1

1

这是因为您的 css 和图像是动态链接的(不以 a 开头/)。这意味着当你去:

/portfolio/

相对 URI 基数从/变为/portfolio/。这意味着如果您链接的图像如下:

src="images/foo.jpg"

而不是加载/images/foo.jpg,你加载/portfolio/images/foo.jpg

更改您的链接,使其成为绝对链接(以 开头/)或将其添加到页面的标题中:

<base href="/" />
于 2013-10-10T02:52:59.323 回答