url重写目录问题(htaccess)

发布于 2024-09-25 12:08:40 字数 480 浏览 2 评论 0原文

早上好。

我目前在我的 .htaccess 中有这个小规则

RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)$ /brochure.php?cat_path=$1 [L]

(我只是在这里使用数字,稍后将是类别名称。)

这完美地重定向,但是当它这样做时,我在目录中的所有内容现在都会失败(css,js,图像) ,包括等)

我理解这个问题(它抛弃了目录结构)。

将规则更改为此解决了图像、CSS 和 JS 问题。

RewriteRule ^([0-9]+)$ brochure.php?cat_path=$1 [L]

但这不是我真正想要的。

进行 url 重写和维护目录结构的正确方法是什么?

谢谢,我已经搜索了以前的问题,但找不到合适的答案。

Good morning.

I currently have this little rule in my .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)$ /brochure.php?cat_path=$1 [L]

(i'm just using numbers for example here, will be category names later.)

This redirects perfectly, but when it does, everything I have in directories now fail (css, js, images, includes etc)

I understand the issue (it's throwing the directory structure off).

Changing the rule to this solves the images, css and JS problem.

RewriteRule ^([0-9]+)$ brochure.php?cat_path=$1 [L]

But it's not what I want really.

What's the correct way to do url rewrites and maintain directory structure?

Thankyou, I have search for through previous questions, but couldn't find a suitable answer.

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

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

发布评论

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

评论(2

挥剑断情 2024-10-02 12:08:40

您必须使用绝对路径或相对于 webroot 的路径,例如:

<img src="http://example.com/image.gif" alt="" />
<img src="/images/image.gif" alt="" />

如果您知道您的图像始终是一个目录,那么这也是一个选项:

<img src="../images/image.gif" alt="" />

You have to use absolute paths or paths relative to the webroot, like:

<img src="http://example.com/image.gif" alt="" />
<img src="/images/image.gif" alt="" />

If you know that your images are always a directory up, this will be an option too:

<img src="../images/image.gif" alt="" />
允世 2024-10-02 12:08:40

虽然我真诚地推荐 Lekensteyn 的答案,但还有另一种解决方案。您的 mod_rewrite 规则基本上将 /brochure.phpcat_path=123 移动到 /brochure/123。您只需修复相对 URL 并设置正确的路径即可。您必须了解这些路径是由浏览器解析的,因此实际的服务器文件系统结构与它无关。

例如: css/style.css 将变为 ../css/style.css

Although I honestly recommend Lekensteyn's answer, there's also another solution. Your mod_rewrite rule basically moves /brochure.phpcat_path=123 to /brochure/123. You can simply fix your relative URLs and set the correct path. Your must understand that these paths are parsed by the browser so the actual server file system structure has nothing to do with it.

E.g.: css/style.css will become ../css/style.css

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