我的htaccess配置有什么问题?

时间:2013-07-18 16:22:15

标签: php .htaccess

这是我的web-root的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

这是我在使用http://code.google.com/p/minify/

的/ min目录中使用的那个
<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>

现在我有两个问题:

  1. Google无法访问root中的Google-Site-Verification-File,因为它已被重写
  2. 我想将子域名用于cookie-freeness,所以我已将i.domain.com和s.domain.com添加到我的服务器配置中,但如果我访问s.domain.com/min,则会重定向到web-root。
  3. 感谢您的帮助!

1 个答案:

答案 0 :(得分: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]
相关问题