Apache2 中的嵌套 URL 和重写规则

发布于 2024-08-04 19:09:56 字数 651 浏览 7 评论 0原文

我需要一些有关重写规则和嵌套 URL 的帮助。

我正在为我的网站使用 TikiWiki,并且正在为我的项目设置 SE 友好的 URL。具体来说,我对 www.example.com/projects 使用以下重写规则,以指向列出 example 中托管的所有项目的页面。

RewriteRule ^Projects$  articles?type=Project  [L]

这很好用。

现在,我想将 www.example.com/projects/project1 指向一个特定的项目。 我有这个重写规则

RewriteRule ^(Projects/Project1)$     tiki-read_article.php?articleId=6

这有效,但部分有效。内容全部呈现为文本,但主题 - 图像/ css 等都进行了折腾 - 页面完全是文本。

我知道发生这种情况是因为主题/ css/图像中的相对路径都将项目作为基本文件夹而不是网站的根目录。

我不想触及 CMS 部分 - 更改文件中的主题/ css/ 图像路径,更多是出于可升级性的原因。

有人可以帮助我理解并编写一个规则,以便上面的嵌套 URL 起作用吗?

问候, 拉达

I need some help with rewrite rules and nested URLs.

I am using TikiWiki for my website and am in the process of setting up SE friendly URLs for my projects. Specifically, I have the following rewrite rule for www.example.com/projects to point to a page that lists out all the projects hosted in example.

RewriteRule ^Projects$  articles?type=Project  [L]

This works fine.

Now, I would like to point www.example.com/projects/project1 to point to a specific project.
I have this rewrite rule

RewriteRule ^(Projects/Project1)$     tiki-read_article.php?articleId=6

This works, but partially. The content is all rendered as text but the theme - images/ css etc all go for a toss - the page is completely in text.

I understand that this happens 'cause the relative paths in the theme/ css/ images all refer to Projects as the base folder instead of the root of the website.

I don't want to touch the CMS portion - change the theme/ css/ image paths in the files, more for reasons of upgradability.

Can someone help me understand and write a rule so that the above nested URL works?

Regards,
Radha

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

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

发布评论

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

评论(2

桃扇骨 2024-08-11 19:09:56

您需要更改 CMS 或为主题/CSS/图像文件编写重写规则。例如,如果您的图像位于站点内的 /images/ 目录中,请尝试

RewriteRule ^Projects/(themes/.*)$ \1

或可能更好。

Alias /Projects/themes /themes

但是,如果是我,我仍然会编辑 CMS 配置。

You need to either change the CMS or write rewrite rules for your theme/CSS/image files. For example, if your images are in the /images/ directory within the site, try

RewriteRule ^Projects/(themes/.*)$ \1

or perhaps better

Alias /Projects/themes /themes

But still, I'd edit the CMS configuration if it were me.

痴骨ら 2024-08-11 19:09:56

相对 URL 在当前文档 URL 的基础 URL 的基础上解析为绝对 URL。因此,在您的情况下,基本 URL 是 /projects/project1 而不是 /projects 尽管您的文件实际上位于那里。因为客户端只使用 URL,对实际的文件系统一无所知。当前文档的 URL 为 /projects/project1

因此,请使用带有绝对 URL 路径 (/projects/css/...) 的 URL 引用,而不是相对路径。

Relative URLs are resolved to absolute URLs on the base of the base URL that is the current document’s URL. So in your case the base URL is /projects/project1 and not /projects although your files are actually located there. Because the client uses only URLs and has no clue about the actual file system. And the current document’s URL is /projects/project1.

So use URL references with an absolute URL path (/projects/css/…) instead of relative ones.

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