PHP 使用 .htaccess 修复相对图像路径
我有一个 php 文件,例如 www.example.com/folder/test.php
上面的文件 (test.php) 包含行
include($_SERVER['DOCUMENT_ROOT']. $page);
$page = /folder2/.$directory1./.$directory2./.index.php
$directory1
和$directory2
都是随机的。
但是,
索引页上有一个图像,仅引用该图像作为源。
例如 src="image.bmp"
那么图像的 url 实际上会像这样显示...... www.example.com/folder/image.bmp
它应该像这样显示...... www.example.com/folder2/.$directory1./.$directory2./image.bmp
除了使用绝对路径之外,还有其他方法可以解决此问题吗? 有数百万个目录,我们希望纠正问题而不是纠正问题(即使我们会同时做这两件事)。
我可以在查找图像的目录中放置一个 htaccess 文件来重定向它吗?
发件人:www.example.com/folder/
至:www.example.com/folder2/.$directory1./.$directory2./
I have a php file, for example www.example.com/folder/test.php
The file above (test.php) has the line
include($_SERVER['DOCUMENT_ROOT'].$page);
$page = /folder2/.$directory1./.$directory2./.index.php
$directory1
and $directory2
are all random.
However,
The index page has an image on it that just references the image as the source.
For Example src="image.bmp"
So what happens is the image's url actually shows up like this...www.example.com/folder/image.bmp
And it should show up like this...www.example.com/folder2/.$directory1./.$directory2./image.bmp
Is there a way to fix this besides using absolute paths?
There are millions of directories and we would like to correct the issue rather than correct the problem (even though we will do both).
Can I place an htaccess file in the directory its looking for the image in to redirect it?
FROM: www.example.com/folder/
TO: www.example.com/folder2/.$directory1./.$directory2./
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想这样做,您应该动态更改 .htaccess 或在其中指定任何可能的
$directory1/$directory2
组合。在我看来,最好的方法是将文件index.php
中该图像的src
更改为以下内容:If you want to do that, you should either dynamically change the .htaccess or specify in it any possible
$directory1/$directory2
combination. In my opinion, the best way to do this is to change thesrc
of that image in the fileindex.php
to something like: