重写规则在 .htaccess 中不起作用

Rewrite rule not working in .htaccess

我有以下 .htaccess,我正在尝试对我网站的 url.

进行 SEO 重写
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?mysite.com/.*$ [NC]
#RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
AddDefaultCharset utf-8

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=37739520, public"
</FilesMatch>

#RewriteCond /%{REQUEST_FILENAME}.php -f

#Redirige con un 302 tutte le richieste da pagine HTML a pagine php
RewriteRule (.*).htm$ /.php [R=301,L]

ErrorDocument 400 /errore/errore.php?error=400&url=%{HTTP_REFERER}
ErrorDocument 401 /errore/errore.php?error=401&url=%{HTTP_REFERER}
ErrorDocument 403 /errore/errore.php?error=403&url=%{HTTP_REFERER}
ErrorDocument 404 /errore/errore.php?error=404&url=%{HTTP_REFERER}
ErrorDocument 500 /errore/errore.php?error=500&url=%{HTTP_REFERER}


RewriteEngine On    

#-------------------------------
#Fix Language subfolders
#-------------------------------
#empty url -> redirect to it/
RewriteCond %{QUERY_STRING} !lang=(it|en)
#RewriteRule ^$ it/ [R=301,L]

#url is language made by 2 chars like '/it' or '/en' -> redirect to /it/ or /en/ (adding slash)
RewriteRule ^([a-zA-Z]{2})$ / [R=301,L]

# now all urls 2 chars long -> parse them
# old RewriteRule ^([a-zA-Z]{2})$  // [QSA]
RewriteRule ^([a-zA-Z]{2})/(.*)$  /?lang=&%{QUERY_STRING} [QSA]

#-------------------------------
# SEO rescripting
#------------------------------- 
RewriteRule ^partita/(.*)$ /analizza-partita.php?partita=&%{QUERY_STRING} [L,QSA]
RewriteRule ^statistiche/partita/(.*)$ /analizza-partita.php?partita=&%{QUERY_STRING} [L,QSA]    
RewriteRule ^squadra/(.*)$ /team/ [L,QSA]
RewriteRule ^team/(.*)$ /squadra.php?id=&%{QUERY_STRING} [L,QSA]    

除了以下 url:

以外,一切正常
www.mysite.com/it/squadra/12345

有了这个,我总是 404 错误,而不是预期的:

www.mysite.com/squadra.php?lang=it&id=12345

天哪,为什么?

您的问题似乎是由于选项 MultiViews

使用 .htaccess 顶部的这一行将其关闭:

Options -MultiViews

选项 MultiViews(参见 http://httpd.apache.org/docs/2.4/content-negotiation.html)由 Apache's content negotiation module 使用,它在 之前 mod_rewrite 运行并使 Apache 服务器匹配文件的扩展名。因此,如果 /file 是 URL 那么 Apache 将提供 /file.php.