我只是将我的网站移动到我的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.jpginstead of accessing the image from the url
http://localhost/slider-images/test/img-1.jpgI 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!
更多推荐
发布评论