Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 基本URL重写:如何让css链接、img src等忽略它?_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 基本URL重写:如何让css链接、img src等忽略它?

.htaccess 基本URL重写:如何让css链接、img src等忽略它?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个网站运行在localhost/pm上,并且RewriteBase被正确设置为/pm/。我的文档中有一个链接标记: 当url为localhost/pm或localhost/pm/foo时,CSS工作正常。但是,当URL中有更多斜杠时,例如localhost/pm/foo/bar如果样式表更改为foo/themes/default/css/default.css,则相对URL 我如何在不必在link标记中添加某种PHP路径解析的情况下使其工作 # invoke rewrite engine

我有一个网站运行在
localhost/pm
上,并且RewriteBase被正确设置为
/pm/
。我的文档中有一个链接标记:

当url为
localhost/pm
localhost/pm/foo
时,CSS工作正常。但是,当URL中有更多斜杠时,例如
localhost/pm/foo/bar
如果样式表更改为
foo/themes/default/css/default.css
,则相对URL

我如何在不必在link标记中添加某种PHP路径解析的情况下使其工作

# invoke rewrite engine
RewriteEngine On
RewriteBase /pm/

# Protect application and system files from being viewed
RewriteRule ^(?:system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
编辑:

基本上我现在需要的是: 如果请求包含文件夹名
/themes/
则废弃
/themes/
之前的所有内容,并将其余内容重写为
/pm/themes/..

我这样试过:
RewriteRule^.*(/themes/*)$/pm/themes/$1
,但我遇到了一个内部服务器错误。为什么?


如果我这样做:
RewriteRule^.*(/themes/*)$/pm/themes/
(即从末尾删除$1)并使用URL
http://localhost/pm/foo/themes/foo/
生成的物理位置为
http://localhost/pm/themes
这也是人们所期望的,这反过来意味着至少我的正则表达式是正确的。我遗漏了什么?

您可能需要在重写规则之前添加以下行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
仅当请求的文件或目录不存在时,它才会评估您的重写规则


您应该发布您的
.htaccess
文件,以便我们提供更好的建议您可能需要在您的
重写规则之前添加以下行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
仅当请求的文件或目录不存在时,它才会评估您的重写规则


您应该发布您的
.htaccess
文件,以便我们提供更好的建议重写规则几乎是正确的

RewriteRule ^.*(/themes/.*)$ /pm/themes/$1
这重写了
http://localhost/pm/foo/themes/default/css/default.css
http://localhost/pm/themes/themes/default/css/default.css
,这是一个太多的主题。用这个代替

RewriteRule /themes/(.*)$ /pm/themes/$1 [L]
但是现在你有一个无休止的重写循环,因为
/pm/themes/。
被一次又一次地重写。为了防止这种情况,您需要一个
RewriteCond
排除
/pm/themes

RewriteCond %{REQUEST_URI} !^/pm/themes/
RewriteRule /themes/(.*)$ /pm/themes/$1 [L]

现在请求只重写一次,您就完成了。

重写规则几乎是正确的

RewriteRule ^.*(/themes/.*)$ /pm/themes/$1
这重写了
http://localhost/pm/foo/themes/default/css/default.css
http://localhost/pm/themes/themes/default/css/default.css
,这是一个太多的主题。用这个代替

RewriteRule /themes/(.*)$ /pm/themes/$1 [L]
但是现在你有一个无休止的重写循环,因为
/pm/themes/。
被一次又一次地重写。为了防止这种情况,您需要一个
RewriteCond
排除
/pm/themes

RewriteCond %{REQUEST_URI} !^/pm/themes/
RewriteRule /themes/(.*)$ /pm/themes/$1 [L]

现在请求只被重写一次,您就完成了。

您必须使用RewriteCond将css从重写中排除,请参阅此答案或重写css请求,请参阅“没有帮助”。但是,使用标记确实可以。请注意,在使用
base
标记时,请参阅以了解详细信息。如果您的css文件位于
/pm/themes/default/css/
下面,您也可以重写这些文件。@OlafDietsche哎哟,锚问题是件坏事。你知道为什么你第一条评论中的解决方案对我不起作用吗?这可能是服务器配置问题吗?根据这个类似的问题:到目前为止,我的问题无法通过建议的措施解决。我已经进一步阐述了我的问题,请参见编辑。您必须使用RewriteCond排除css被重写,请参见此答案或重写css请求,请参见没有帮助。但是,使用标记确实可以。请注意,在使用
base
标记时,请参阅以了解详细信息。如果您的css文件位于
/pm/themes/default/css/
下面,您也可以重写这些文件。@OlafDietsche哎哟,锚问题是件坏事。你知道为什么你第一条评论中的解决方案对我不起作用吗?这可能是服务器配置问题吗?根据这个类似的问题:到目前为止,我的问题无法通过建议的措施解决。我已经进一步阐述了我的问题,请参见编辑。