2013-07-18 44 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代碼?這與重寫規則無關。 –