htaccess文件,合并两组重写规则

时间:2014-11-15 21:33:42

标签: apache .htaccess mod-rewrite

嗨,我感谢任何能够帮助我使用这个mod_rewrite代码的人。我对从头开始编写htaccess非常不熟悉,所以任何帮助都会很棒。

我正在使用此代码来组织我的根目录,允许我将主域的文件放在subduer中:

# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?kinetic-designs.net$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/kd/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /kd/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?kinetic-designs.net$ 
RewriteRule ^(/)?$ kd/index.html [L]

现在,为了使用我的主机提供的CDN,我需要确保在http://www.example.net而不是example.net上加载我的域。所以他们说要使用这段代码:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

这不起作用,因为我很确定它与上面的代码冲突。有人建议如何修改顶部代码块以包含较低的块规则吗?

或者如果你知道一个很好的资源来了解这些规则是如何运作的,那么我很难找到关于这个主题的优质文档。

再次感谢! :)

1 个答案:

答案 0 :(得分:0)

@arkascha是正确的,切换该规则的顺序。

RewriteCond %{HTTP_HOST} ^kinetic-designs.net [NC]
RewriteRule ^(.*)$ http://www.kinetic-designs.net/$1 [L,R=301]
相关问题