【问题标题】:htaccess to fix broken links on local sitehtaccess 修复本地站点上的损坏链接
【发布时间】:2012-03-20 03:24:49
【问题描述】:

因此,在将直播站点移动到本地计算机上进行离线展示后,由于dreamweaver 放入的../ 放错了位置,许多链接都已断开。

它可以在线工作,因为该域的用户无权离开其文档根目录,但在本地却没有。

是否有一个 .htaccess 可以让我在尝试导航到其父级时将根目录限制或重定向回自身?

所以该站点位于xampp/mysite/ 中,并且img src 的值为../images/image.png

所以它在xampp/images/image.png 寻找图像,而不是停留在xampp/mysite/images/image.png 的根目录中

【问题讨论】:

  • 所以来自tld/parent-dir/sub-dir/index.php 的请求具有对解析为tld/parent-dir/image.php 的图像的引用,并且您希望它提供来自tld/parent-dir/sub-dir/image.php 的图像?如果没有,你能举个例子吗

标签: .htaccess localhost hyperlink


【解决方案1】:

我假设您的所有图像都在/xampp/mysite/images 目录中。

如果是这样,那么您可以尝试将以下内容添加到您网站根目录中的 .htaccess 文件中。

RewriteEngine on
RewriteBase /

#if request is not in xampp/mysite/images/
RewriteCond %{REQUEST_URI} !^/xampp/mysite/images/ [NC]
#rewrite images to /xampp/mysite/images
RewriteRule /(.+\\.(png|jpg|gif))$ /xampp/mysite/images/$1 [NC,L]

【讨论】:

  • 图片只是一个例子。链接也会发生这种情况,即<a href="../index.php"> 会转到xampp/index.php 而不是xampp/mysite/index.php
猜你喜欢
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 1970-01-01
  • 2018-08-28
  • 1970-01-01
相关资源
最近更新 更多