重写基地基于规则的PHP [英] Rewrite base rule- php
问题描述
内部网址: example.com/abc/xyz/rule.php?price=1&pass=2
外部URL: example.com/abc/xyz/rule/1/2
不过,CSS,JS文件都没有进入外部URL效果。 我的.htaccess文件:
RewriteEngine叙述上
的RewriteBase /example.com/abc/
重写规则^规则/([0-9] +)/([0-9] +)/ $ rule.php价格= $ 1安培;?通过= $ 2
问题是相对URL是由客户端和服务器无法解析。而基本URL,相对URL被得到解决,是当前文档的URL。而在你的情况基本URL(路径) / ABC / XYZ /规则/ 1/2
,而不是 /abc/xyz/rule.php ?价格= 1安培;通过= 2
现在可以通过多种方式来解决这个问题:
- 使用,可从实际的基础URL
正确解析相对URL / ABC / XYZ /规则/ 1/2
- 是独立于基础URL使用绝对路径
- 在塔子使用的基本URL HTML的
BASE
元素
Internal URL: example.com/abc/xyz/rule.php?price=1&pass=2
External URL: example.com/abc/xyz/rule/1/2
But the css, js files are not coming into effect in the external URL. My .htaccess file:
RewriteEngine On
RewriteBase /example.com/abc/
RewriteRule ^rule/([0-9]+)/([0-9]+)/?$ rule.php?price=$1&pass=$2
The "problem" is that relative URLs are resolved by the client and not by the server. And the base URL, the relative URLs are resolved from, is the URL of the current document. And in your case the base URL (path) is /abc/xyz/rule/1/2
and not /abc/xyz/rule.php?price=1&pass=2
.
Now you have several ways to solve this:
- Use relative URLs that are correctly resolvable from the actual base URL
/abc/xyz/rule/1/2
- Use absolute URLs that are independent from the base URL
- Alter the base URL using HTML’s
BASE
element
这篇关于重写基地基于规则的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!