php - .htaccess 只出现 html 而没有 CSS 或 PHP

标签 php html css .htaccess

我一直在网上想知道如何使用 htacces(真的很难学)。当我潜伏在互联网上时,我发现了这个:http://www.generateit.net/mod-rewrite/

好吧,我插入了我的 url(在本地主机上工作):
empresa.com/index.php?p=sub_artigo&id=1&cat=Mercearia

它给了我这个(默认所有选项):
http://empresa.com/sub_artigo/5/Mercearia.html

.htacces 代码是这样的:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$/index。 php?p=$1&id=$2&cat=$3 [L]

当我在 php 中生成 url 时,我会这样做

<a href=\"sub_artigo/".$response2['ID_sub_artigo']."/".$response2['url'].".html\">$response2[nome_sub_artigo]</a>

然后,当我单击该按钮时,它看起来像只有 html。 示例:http://s14.postimg.org/wr137fx4x/htacces_error.jpg

知道发生了什么吗?

最佳答案

看起来您正在为您的 Assets (图像、javascript、css)使用相对链接。

这意味着当您从新的 url 中查找 css/my_stylesheet.css 时,浏览器将请求一个类似于 http://empresa.com/sub_artigo/5/的 url css/my_stylesheet.css.

最简单的解决方案是始终为您的资源使用绝对 URL,例如 /css/my_stylesheet.css 等。

关于php - .htaccess 只出现 html 而没有 CSS 或 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17702084/

相关文章:

php - 在 Laravel 中测试时获取作为用户的 ID

javascript - 通过 ant 执行 JavaScript (HTML) 文件并将输出重定向到文件

html - Ionic 在 ionic View 中将标题和顶部导航栏放在哪里?

html - :before work in css?如何

css - 找不到弄乱页面的结束 div 标签

html - 打开 paper-dropdown-menu 时滚动网页

php - 将 RSA 公钥从 XML 转换为 PEM (PHP)

PHP 多对象取消引用

css - 在 Angular 中更新 CSS 变量

PHP 仅对数字和字符进行字符串编码/解码