没有{%Document_Root}的Mod_rewrite

时间:2014-08-06 16:14:13

标签: apache .htaccess mod-rewrite

我曾经将我的所有域名指向我的网站空间根目录。并使用这样的htaccess文件将不同的域指向不同的文件夹

RewriteCond %{HTTP_HOST} ^new.vea.?re.?[net|de]?(.*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/veare/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/veare/$1 -d
RewriteRule ^(.*)$ veare/$1 [L]
# rewrite parameters that are neither files nor folders
RewriteCond %{HTTP_HOST} ^new.vea.?re.?[net|de]?(.*)?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ veare/index.php?/$1 [L]

我现在的问题是,我的新网络提供商没有设置%{DOCUMENT_ROOT},所以这个脚本不起作用。有没有解决方法?

就像这样。

www.test.com/css/style.css
1.域名指向root 2.如果存在root/test.com/css/style.css,则只需抓取此文件,即重定向到子文件夹test.com
3.如果既不是文件也不是文件夹,它应该只指向子文件夹root/test.com/index.php中的index.php

如何在没有%{DOCUMENT_ROOT}的情况下解决它?

1 个答案:

答案 0 :(得分:0)

好,

轻松修复,使用<?php phpinfo(); ?>,它应该确实告诉你真正的文档根。例如。 customer/123445_12345。现在你可以在你的htaccess中使用它。请注意,我还必须使用%{REQUEST_URI}代替%{REQUEST_FILENAME}来获取完整路径,例如/css/app.css

RewriteCond %{HTTP_HOST} ^test.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test/
RewriteCond /customer/123445_12345/test/public/%{REQUEST_URI} !-f
RewriteCond /customer/123445_12345/test/public/%{REQUEST_URI} !-d
RewriteRule ^(.*)$ /formandsystem/cms/test/index.php?/%{REQUEST_URI} [L]
RewriteCond /customer/123445_12345/test/public/%{REQUEST_URI} -f [OR]
RewriteCond /customer/123445_12345/test/public/%{REQUEST_URI} -d
RewriteRule ^(.*)$ /test/public/%{REQUEST_URI} [L]