2017-03-23 38 views
1

我有以下.htaccess,我正在嘗試對我的網站的URL進行SEO重新編程。重寫規則無法在.htaccess中工作

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 

神,爲什麼?

+0

squadra.php存在,它位於根文件夾中。 – BeeBee

+0

所以'www.myste.com/squadra.php?lang = it&id = 12345'在瀏覽器中工作正常嗎?你的規則適用於我的Apache – anubhava

+0

是的,它工作正常。這就是爲什麼我不明白原因。此外,我不明白爲什麼「團隊」的作品,但「班」不是! – BeeBee

回答

1

您的問題似乎是由於選項MultiViews

關掉它使用在你的.htaccess的頂部這一行:

Options -MultiViews 

選項MultiViews(見http://httpd.apache.org/docs/2.4/content-negotiation.html)所使用的Apache's content negotiation modulemod_rewrite之前運行,使文件的Apache服務器匹配擴展。所以如果/file是URL,那麼Apache將服務於/file.php

+1

YEEES,這是問題所在。它現在正常工作!太感謝了。 – BeeBee