Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache 使用动态创建的子域和mod_重写时链接css和javascript文件_Apache_Mod Rewrite - Fatal编程技术网

Apache 使用动态创建的子域和mod_重写时链接css和javascript文件

Apache 使用动态创建的子域和mod_重写时链接css和javascript文件,apache,mod-rewrite,Apache,Mod Rewrite,我需要一些帮助,找出如何链接css和javascript文件时使用我的网站子域 我们有一个CMS,允许用户拥有自己的子域,例如user1.mydomain.com。我们希望用户被定向到site_index.php页面,并在键入子域时将子域作为querystring参数传递,这就是为什么我们在apache配置中有以下mod_重写规则 下面是apache httpd.conf文件中的mod_重写: <IfModule mod_rewrite.c> Options +FollowSy

我需要一些帮助,找出如何链接css和javascript文件时使用我的网站子域

我们有一个CMS,允许用户拥有自己的子域,例如user1.mydomain.com。我们希望用户被定向到site_index.php页面,并在键入子域时将子域作为querystring参数传递,这就是为什么我们在apache配置中有以下mod_重写规则

下面是apache httpd.conf文件中的mod_重写:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   ####RewriteBase /
   RewriteCond %{HTTP_HOST} !www.mydomain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mydomain.com [NC]
   RewriteRule ^(.*)$  /administrator/sites_index.php?subdomain=%2 [L]
</IfModule>
在sites_index.php页面中,我们获取子域并验证它,然后呈现该特定子域的html。每个用户都可以有自己的css模板。我遇到的问题来自于对.css文件和.js文件使用相对路径。 以下是我想链接到它们的方式:

<link href="public_site_templates/css_templates/common.css" type="text/css" rel="stylesheet">
<script src="public_site_templates/javascript/common.js" type="text/javascript"></script>
上面的链接会加载HTML,但是css和javascript永远不会链接起来

如果我硬编码路径,如下所示:

<link href="http://www.mydomain.com/administrator/public_site_templates/css_templates/common.css" type="text/css" rel="stylesheet">
    <script src="http://www.mydomain.com/administrator/public_site_templates/javascript/common.js" type="text/javascript"></script>
然后一切都正常连接起来。我检查了相对路径,所有东西都应该连接起来,但它没有

我能做些什么来解决这个问题吗?我有没有更好的办法?任何帮助都将不胜感激

谢谢

您可能正在寻找html标记

假设你试过这样的东西,但没用

<link href="/administrator/public_site_templates/css_templates/common.css" type="text/css" rel="stylesheet">
<script src="/administrator/public_site_templates/javascript/common.js" type="text/javascript"></script>

只需忽略js和css文件

我添加了:RewriteCond%{REQUEST_URI}!*。js | css$[NC]:

我最喜欢的检查regexp的工具:

别忘了选择eregPOSIX而不是pregPCRE


我可以请您在问题中添加重写日志吗?

尝试了此操作,但得到了相同的结果。不管怎样,谢谢你的帮助。基本原则是,只有当is与以css或js=>!\结尾的regexp不匹配时,才应用这些规则。css | js$mayb我的regexp不太好,但是我很确定如果你找到了一个符合这个原则的合适的,那么一切都会工作的。这是可行的,但与我以前对url进行的硬编码没有太大区别。谢谢你的回复。嗯,我想我不知道你在找什么。您希望URL的外观如何?
<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC]
   RewriteCond %{HTTP_HOST} !www.mydomain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mydomain.com [NC]
   RewriteRule ^(.*)$  /administrator/sites_index.php?subdomain=%2 [L]
</IfModule>
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On