2013-07-18 48 views
0

这是我的htaccess的文件为Web根目录:我的htaccess配置有什么问题?

<IfModule mod_deflate.c> 
    # Force compression for mangled headers. 
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping 
    <IfModule mod_setenvif.c> 
     <IfModule mod_headers.c> 
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding 
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding 
     </IfModule> 
    </IfModule> 
    # Compress all output labeled with one of the following MIME-types 
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter` 
    # and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines 
    # as `AddOutputFilterByType` is still in the core directives). 
    <IfModule mod_filter.c> 
     AddOutputFilterByType DEFLATE application/atom+xml 
     application/javascript 
     application/json 
     application/rss+xml 
     application/vnd.ms-fontobject 
     application/x-font-ttf 
     application/x-web-app-manifest+json 
     application/xhtml+xml 
     application/xml 
     font/opentype 
     image/svg+xml 
     image/x-icon 
     text/css 
     text/html 
     text/plain 
     text/x-component 
     text/xml 
    </IfModule> 
</IfModule> 

# Expire images header 
ExpiresActive On 
ExpiresDefault A0 
ExpiresByType image/gif A24592000 
ExpiresByType image/png A24592000 
ExpiresByType image/jpg A24592000 
ExpiresByType image/jpeg A24592000 
ExpiresByType image/x-icon A24592000 
ExpiresByType text/css A24592000 
ExpiresByType text/javascript A24592000 

RewriteEngine On 

#do not rewrite for subdomains 
RewriteCond %{HTTP_HOST} ^(www\.)?legendaily\.com$ 

#redirect non-www to www 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

#only rewrite if it's not a file and not /login/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !^/login/ 

#rewrite /a/1 to /index.php?action=a&urlId=1 
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&urlId=$2 [L,QSA] 

#rewrite /a to /index.php?action=a 
RewriteRule ^([^/]+)/?$ index.php?action=$1 [L,QSA] 

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /path/to/.htpasswd 
AuthGroupFile /dev/null 
require valid-user 

,这是一个我在/ min的目录,我使用http://code.google.com/p/minify/

<IfModule mod_rewrite.c> 
RewriteEngine on 

# You may need RewriteBase on some servers 
#RewriteBase /min 

# rewrite URLs like "/min/f=..." to "/min/?f=..." 
RewriteRule ^([bfg]=.*) index.php?$1 [L,NE] 
</IfModule> 
<IfModule mod_env.c> 
# In case AddOutputFilterByType has been added 
SetEnv no-gzip 
</IfModule> 

使用现在我有2个问题:

  1. 的谷歌站点,验证,文件的根不能由谷歌,因为它改写访问
  2. 我想使用子域名来获得无cookie的功能,所以我将i.domain.com和s.domain.com添加到了我的服务器配置中,但是如果我访问s.domain.com/min,它会被重定向到网络的根。

感谢您的帮助!

回答

0

行:

#do not rewrite for subdomains 
RewriteCond %{HTTP_HOST} ^(www\.)?legendaily\.com$ 

可能需要更改为:

#do not rewrite for subdomains 
RewriteCond %{HTTP_HOST} !^.+\.legendaily\.com$ [NC] 

所以它匹配下一条规则不包括子域

条件只能获得适用于紧随其后的重写规则,因此您需要重复适用于多个规则的规则。最后一条规则:

RewriteRule ^([^/]+)/?$ index.php?action=$1 [L,QSA] 

没有任何条件,所以会盲目地改写一切/index.php,包括存在的文件。所以你至少需要!-f检查:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/?$ index.php?action=$1 [L,QSA] 
+0

谢谢!不幸的是,我仍然从http://s.domain.com/min/b=js&f=fastclick.js,bootstrap.min.js,jquery.masonry.min.js,exif2.js,bootstrap-tagmanager得到以下答案.js,custom.js,editor.js,preview.js: <?php /** *前端控制器用于默认Minify实施 * *请勿编辑!配置此实用程序通过config.php和groupsConfig.php * * @package Minify */ –

+0

有更多的想法? –

+0

@RaphaelJeger至于你为什么看到原始的PHP代码?这与重写规则无关。 –