douao1579
douao1579
2012-09-19 11:12

.htaccess文件,路径被正确重定向,但未加载图像和CSS

已采纳

Hi I am using the following lines in my .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteBase /coaster/CoasterInsider/
 RewriteRule signup$ index.php?page=signup [L,NC]
 RewriteRule login$ index.php?page=loginHandle [L,NC]
 RewriteRule u/(.*)$ index.php?page=profile&username=$1 [L,NC]

The path is getting redirected properly, but the css,flash and images are not loading. Also if I use the following '/' after any url say,

RewriteRule signup(/?)$ index.php?page=signup [L,NC]

It's not finding any page there, i.e. error 404. I just want my htaccess file to work for both /signup and /signup/

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dryb38654 dryb38654 9年前

    When browser displays:

    http://example.com/coaster/CoasterInsider/signup
    http://example.com/coaster/CoasterInsider/signup/
    

    and encounters a relative URL such as:

    <img src="site/images/photo.png">
    

    It translates the relative URL to (respectively):

    http://example.com/coaster/CoasterInsider/site/images/photo.png
    http://example.com/coaster/CoasterInsider/signup/site/images/photo.png
    

    You should use absolute URLs for assets. Make this a habit:

    <img src="/site/images/photo.png">
    

    Alternately you can use the HTML base tag in your pages which tells browsers how to treat relative URLs. Personally I do not recommend it.

    点赞 评论 复制链接分享
  • dongniaoli1822 dongniaoli1822 8年前

    This was advised to, and worked for me, place it inside the <head> tags in your html: <base href="/"> Again, it worked for me, I hope it helps someone else.

    点赞 评论 复制链接分享
  • dqzg62440 dqzg62440 9年前

    Use

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

    to exclude real files and directories from being rewritten.

    You could also add

    RewriteCond %{REQUEST_FILENAME} !-l
    

    to do the same for symlinks.

    点赞 评论 复制链接分享