htaccess directoryindex redirect寻找css错误的地方

时间:2013-03-20 16:31:29

标签: .htaccess rewrite directoryindex

你好在我的htaccesss文件中我把这段代码确保我的目录索引文件设置为

v2013 / index.html中

所以我把这段代码

DirectoryIndex v2013/index.html

然后我希望它看起来像mydomain.com/Welcome,所以我添加..

RewriteEngine On
RewriteRule ^Welcome$ v2013/index.html [L]

我的问题是为什么DirectoryIndex不再工作..我怎么能告诉浏览器在v2013中查找css,因为它是在root中查找。 (我认为是因为重写)所以我的页面是不稳定的.. =(

换句话说,正在寻找

的www.domain.com/css/sheet.css

www.domain.com/v2013/css/sheet.css

答案在这里:

最终法典

DirectoryIndex v2013/index.html

RewriteEngine On

# exclude files already asking for v2013
RewriteCond %{REQUEST_URI} !^/v2013/
RewriteRule ^css/.*$ /v2013/$0
RewriteRule ^js/.*$ /v2013/$0
RewriteRule ^images/.*$ /v2013/$0

RewriteRule ^Bienvenido$ v2013/index.html [L]

2 个答案:

答案 0 :(得分:1)

您可以添加其他RewriteRule,以重写css/js/images/文件

# exclude files already asking for v2013
RewriteCond %{REQUEST_URI} !^/v2013/
RewriteRule ^(?:css|images|js)/.*$ /v2013/$0

答案 1 :(得分:0)

如果使用css文件,请不要键入“css / style.css”,请写“/css/style.css”。添加/将您带到根目录。 html应如下所示:

     <link href="/v2013/css/style.css" rel"stylesheet" type="text/css" />