繁体   English   中英

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

[英]Rewrite rule not working in .htaccess

我有以下.htaccess,我正在尝试对我网站的网址进行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$ /$1.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})$ $1/ [R=301,L]

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

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

一切运作良好,排除以下网址:

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 ,该Apache's content negotiation module mod_rewrite 之前运行,并使Apache服务器匹配文件的扩展名。 因此,如果/file是URL,则Apache将提供/file.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM