使用多个值重写.htaccess中的URL

时间:2014-11-05 08:48:03

标签: css apache .htaccess url-rewriting rewrite

我重写了网址

“123.com/search.php”到“123.com/search”使用以下规则

RewriteRule ^search$ search.php

它为我工作。但是,使用规则“123.com/search.php?cat=something”到“123.com/search/something”

RewriteRule ^search/(.*)$ search.php?cat=$1

不能正常工作。

显示错误,如

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://123.com/search/styles/common.css".

Resource interpreted as Scripts but transferred with MIME type text/html: "http://123.com/search/scripts/common.js".

我有那个css& 123.com/styles和123.com/scripts目录中的js文件。

另外,我需要帮助重写URL 123.com/search.php?cat=something&filter=subcat到123.com/search/something/subcat

1 个答案:

答案 0 :(得分:2)

问题在于HTML。您可能有样式表和JavaScript文件链接如下:

<link rel="stylesheet" href="styles/common.css">
<script src="scripts/common.js"></script>

必须将这些(以及所有类似的)网址更改为绝对网址:

<link rel="stylesheet" href="/styles/common.css">
<script src="/scripts/common.js"></script>

<强>解释

当您在搜索页面上时,搜索页面的URL将是:

http://123.com/search/

当浏览器抓取此页面时,会遇到转换为这些网址的相对网址:

http://123.com/search/styles/common.css
http://123.com/search/scripts/common.js

这两个URL都将被服务器重写为:

http://123.com/search/search.php?cat=styles/common.css
http://123.com/search/search.php?cat=scripts/common.js