Apache2 中的嵌套 URL 和重写规则
我需要一些有关重写规则和嵌套 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要更改 CMS 或为主题/CSS/图像文件编写重写规则。例如,如果您的图像位于站点内的
/images/
目录中,请尝试或可能更好。
但是,如果是我,我仍然会编辑 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, tryor perhaps better
But still, I'd edit the CMS configuration if it were me.
相对 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.