mod_rewrite 多个假子目录

发布于 2024-12-26 12:50:54 字数 752 浏览 2 评论 0原文

抱歉,如果这是一个非常愚蠢的问题 - 我在任何地方都找不到答案...

我将测试文件存储在名为“dev”的子目录中,并使用以下重写规则,以便请求 /dev /VAR1/VAR2 将带我到 /index.php?page=VAR1/VAR2,对 /dev/VAR1/ 的请求将带我到/index.php?page=VAR1 (VAR1 和 VAR2 是变量,文件夹/子目录不会真正存在)

RewriteBase /dev
RewriteRule ^([A-Za-z/\-]+)/$ index.php?page=$1

这做得很好 - 我的 index.php 正在获取正确的变量。问题是服务器或页面(或者我不明白什么......)认为我实际上位于不存在的文件夹(或子目录)中,即 VAR1,所以我所有的亲戚(如果这是正确的词)图像、链接、CSS 和脚本等的地址

<link rel="stylesheet" type="text/css" href="./sitefiles/mystyles.css" />

都像 /dev/VAR1/sitefiles/mystyles.css 一样工作 - 基本上,服务器认为它实际上在“假”文件夹。

有没有办法可以继续在 mod_rewrite 中使用这些相对地址,或者我是否必须使用带有完整路径的“绝对”地址?

感谢您的帮助!

Sorry if this is a really dumb question - I can't find the answer anywhere...

I'm storing my test files in a subdirectory called 'dev', and using the following rewrite rule so that requests to /dev/VAR1/VAR2 will take me to /index.php?page=VAR1/VAR2, and requests to /dev/VAR1/ will take me to /index.php?page=VAR1
(VAR1 and VAR2 are variables, and the folders/subdirectories won't really exist)

RewriteBase /dev
RewriteRule ^([A-Za-z/\-]+)/$ index.php?page=$1

This is doing it fine - my index.php is getting the right variables. The problem is that the server or page (or I don't understand what...) thinks I'm actually in the non-existent folder (or subdirectory) which is VAR1, so all my relative (if that's the right word) addresses for images and links and css and scripts etc

<link rel="stylesheet" type="text/css" href="./sitefiles/mystyles.css" />

all work as if they were /dev/VAR1/sitefiles/mystyles.css - basically, the server thinks it's actually in the 'fake' folder.

Is there a way I can continue to use these relative addresses with my mod_rewrite, or do I have to use 'absolute' addresses with the complete path?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半山落雨半山空 2025-01-02 12:50:54

我们在配置中使用相同的东西,并将假别名重写为index.php?something=$1 我们必须将CSS文件放入DocumentRoot的/styles/中,并且不要使用相对./路径使用绝对路径像 href="/sitefiles/mystyles.css" 一样它应该可以正常工作。

We're using the same stuff with our configuration and rewriting fake aliases to index.php?something=$1 we have to put our CSS files into the /styles/ of the DocumentRoot and don't use relative ./ path use the absolute path like href="/sitefiles/mystyles.css" it should work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文