URL重写localhost上的相对URL(URL Rewrite for relative URLs on localhost)

编程入门 行业动态 更新时间:2024-10-26 19:28:11
URL重写localhost上的相对URL(URL Rewrite for relative URLs on localhost)

我只是将我的网站移动到我的Apache Web服务器根目录下的一个文件夹(称为测试),现在我在页面尝试获取不同的资源时收到404错误。 当我查看网址时 - 它们似乎指向服务器的根,因为它们是根相对URL(而不是指向根目录中的文件夹[test])。

例如:当我的网站的索引页面具有对图像的引用时

<img src="/images/img-1.jpg" alt="Image 1" />

执行页面时,尝试从以下URL获取图像

http://localhost/slider-images/img-1.jpg

而不是从网址访问图像

http://localhost/slider-images/test/img-1.jpg

我一直在尝试各种选项,比如有一个ReWriteBase等,但这似乎不起作用!

相反,我将资源路径改为绝对路径,但这对我来说只是为所有资源做了太多工作!

<img src="./images/img-1.jpg" alt="Image 1" />

任何帮助深表感谢。

谢谢

更新

之前已经发布了类似的问题,但我没有解决问题的响应使用mod_rewrite将相对URL请求转换为绝对URL请求

I just moved my website to a folder (called test) inside the root of my Apache web server and now I am getting 404 errors while the page tries to fetch different resources. When I looked at the urls - they seem to be pointing to the root of server as they are root relative URLs (as opposed to be pointing to the folder [test] inside the root).

For example: when the index page of my site has a reference to an image like

<img src="/images/img-1.jpg" alt="Image 1" />

The page when executed, tries to fetch the image from the following url

http://localhost/slider-images/img-1.jpg

instead of accessing the image from the url

http://localhost/slider-images/test/img-1.jpg

I have been trying various options like having a ReWriteBase etc, but that doesn't seem to be working!

What works instead is me changing the resource path to be an absolute one, but that is just too much of work for me to do for all the resources!

<img src="./images/img-1.jpg" alt="Image 1" />

Any help is much appreciated.

Thanks

Update

A similiar question has been posted earlier, but I don't a response that solved the issue Converting relative URL requests to absolute URL request using mod_rewrite

最满意答案

经过数小时的故障排除后,我做了一个可以使用临时修复的解决方法。 将它发布在这里以帮助那些可能遇到同样问题的人。

只需将httpd.conf文件中的DocumentRoot更改为指向我移动了我的网站文件以进行测试的子目录。

希望这有助于那些可以使用它的人解决这个问题。

我仍然真的很想知道一种通过htaccess解决根相对URL重写的方法,希望有人能够提供帮助。

谢谢!

After hours of troubleshooting, I did a workaround which can be used a temp fix. Posting it here to help those who possibly could be having the same problem.

Simply changed the DocumentRoot in httpd.conf file to point to the sub-directory where I had moved my website files for testing.

Hope this helps those who can make use it this fix.

I would still be really interested to know of a way to address the root-relative URL rewrites via htaccess and hopefully someone here would be able to help.

Thanks!

更多推荐

本文发布于:2023-08-06 08:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   localhost   URL   URLs   relative

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!