网址重写问题

发布于 2024-08-25 20:07:21 字数 370 浏览 4 评论 0原文

我在 .htaccess 中使用了以下代码,

Options +FollowSymlinks
RewriteEngine On 
RewriteBase /
RewriteRule ^company/aboutus$ aboutus.php  [NC,L]
RewriteRule ^company/contactus$ contactus.php  [NC,L]
RewriteRule ^company/careers$ careers.php  [NC,L]
RewriteRule ^/$ index.php  [NC,L]

上面的代码可以工作,但是 aboutus 页面加载没有任何 css 和图像。没有公司文件夹,我使用公司一词来表示网址可重读性

i have used the following code in .htaccess

Options +FollowSymlinks
RewriteEngine On 
RewriteBase /
RewriteRule ^company/aboutus$ aboutus.php  [NC,L]
RewriteRule ^company/contactus$ contactus.php  [NC,L]
RewriteRule ^company/careers$ careers.php  [NC,L]
RewriteRule ^/$ index.php  [NC,L]

the above code works but aboutus page loading without any css and images. no company folder, i have used company word for url redability

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

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

发布评论

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

评论(3

心如狂蝶 2024-09-01 20:07:21

这是因为浏览器正在尝试在 /company 中查找您的样式表。链接重写的文件时使用绝对 URL(例如 /styles.css),或使用 HTML 标记指定应从何处解析 URL。

This is because the browser is trying to lookup your stylesheet in /company. Use an absolute URL when linking rewritten files (e.g. /styles.css) or use the HTML <base> tag to specify from where the URLs should be resolved.

猥琐帝 2024-09-01 20:07:21

因为您使用的是相对路径,而现在浏览器认为 CSS 不在某个地方。您必须更新链接或将 CSS 文件移动到浏览器认为的级别。您还可以设置基本 href,但我不建议这样做,因为它可能会导致混乱。

Because you're using relative paths and now the browser thinks the CSS is somewhere it's not. You'll have to update your links or move your CSS files to the level the browser thinks it's at. You could also set a base href but I don't recommend that as it can cause confusion down the track.

你是我的挚爱i 2024-09-01 20:07:21

好吧,听起来问题是您输出的 HTML 可能引用相对于 / 的相对路径,而不是 company/ 。您可以使用绝对路径或在 HTML 中执行类似的操作:

<base href = "{your base url}" />

Well, it sounds like the problem is that the HTML you are outputting probably refers to relative paths relative to /, and not company/. You could use absolute paths or do something like this in your HTML:

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