【发布时间】:2012-01-17 10:32:49
【问题描述】:
我使用 winXP 和 AppServ。我的网站根目录上有一个“showitem.php”。一个示例用法:
www.mydomain.com/showitem.php?id=123
我想使用如下链接:www.mydomain.com/item/123
在 .htaccess 中我写下这一行:RewriteRule ^item/([^/]+)$ showitem.php?id=$1
服务器指向showitem.php 并且成功接收到id。但是,主要问题在于 css 和 js 文件。如果我将“css/style.css”设置为“/css/style.css”,页面会显示在 Internet 上,但不会显示在 localhost 上,因为 root 是“localhost”,但文件位于“localhost/mydomain”下。我也尝试过 .css 文件的“!-f”条件,但它没有帮助,据我所知,它不能。为了解决这个问题,我应该将错误的 css 文件解释指向正确的位置,因此我想将客户端请求“item/css/style.css”重定向到其原始位置“css/style.css”。我为localhost添加了以下规则,但还有其他方法吗?
RewriteRule ^item/css/([^/]+)$ /mydomain/css/$1
RewriteRule ^item/img/([^/]+)$ /mydomain/img/$1
【问题讨论】:
标签: css apache rewrite localhost