需要 mod_rewrite URL 信息 [英] mod_rewrite URL info required

查看:28
本文介绍了需要 mod_rewrite URL 信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个 mod_rewrite 的新手.我已经成功地重写了这样的 URL:http://mydomain.com/products/12 到这个:http://mydomain.com/products.php?prodId=12

I am new to this mod_rewrite. I have been successfully able to rewrite the URL something like this: http://mydomain.com/products/12 to this: http://mydomain.com/products.php?prodId=12

但是当我在地址栏中给出 http://mydomain.com/products/12 时,没有加载 css 和 js 文件.

But when I give http://mydomain.com/products/12 in the address bar, the css and js files are not loaded.

但是当我访问 http://mydomain.com/products.php?prodId=12 时,js 和 css 会正确加载.如果我遗漏了什么,请告诉我.

But when I access http://mydomain.com/products.php?prodId=12 the js and css get loaded properly. Please let me know if I am missing something.

我的 .htaccess 如下所示:

My .htaccess looks like this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^products/([0-9][0-9])/$ /products.php?prodId=$1 [L]

我的 css 和 js 文件夹也在同一个文件夹中.

My css and js folders are also in the same folder.

推荐答案

您需要知道相对 URI(因此绝对和相对 URI 路径也是如此)是从基本 URI 解析的,如果未明确声明,则该 URI 是当前文档.

You need to know that relative URIs (thus absolute and relative URI paths too) are resolved from a base URI that is – if not explicitly declared – the URI of the current document.

因此,如果您使用相对 URI foo/bar/products/12 引用外部资源,则会解析为 /products/foo/bar.

So if you reference external resources from /products/12 with the relative URI foo/bar, it’s resolved to /products/foo/bar.

要解决此问题,请使用绝对 URI 路径(以 / 开头)或绝对 URI(以协议开头)或明确设置除当前 URI 之外的基本 URI(请参阅 BASE HTML 元素).但请注意,更改基本 URI 会产生一些副作用,因为它会影响每个相对 URI.

To fix this, use absolute URI paths (beginning with /) or absolute URIs (beginning with the protocol) or set explicitly a base URI other than the current (see BASE HTML element). But note that changing the base URI has some side effects as it affects every relative URI.

这篇关于需要 mod_rewrite URL 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆