网址重写问题
我在 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为浏览器正在尝试在
/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.因为您使用的是相对路径,而现在浏览器认为 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.
好吧,听起来问题是您输出的 HTML 可能引用相对于 / 的相对路径,而不是 company/ 。您可以使用绝对路径或在 HTML 中执行类似的操作:
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: