2017-03-23 11 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]  

すべては、以下のURLを排除して、うまく動作します、

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

神:これにより

www.mysite.com/it/squadra/12345 

、私はいつもの代わりに予想の404エラーをしましたどうして?

+0

squadra.phpが存在し、ルートフォルダにあります。 – BeeBee

+0

「www.myste.com/squadra.php?lang = it&id = 12345」はブラウザでうまく動作しますか?あなたのルールは私のApache上で正常に動作します – anubhava

+0

はい、うまくいきます。これが理由を理解できない理由です。また、私はなぜ "チーム"が動作するのか理解できませんが、 "スクアドラ"はありません! – BeeBee

答えて

1

問題は、オプションMultiViewsに起因するようです。

はあなたの.htaccessの上にこの行を使用して、それをオフにし

mod_rewriteを実行し、ファイルのApacheサーバの一致の拡張機能を作る

Options -MultiViews 

オプションMultiViewshttp://httpd.apache.org/docs/2.4/content-negotiation.htmlを参照)Apache's content negotiation moduleで使用されています。したがって、/fileがURLの場合、Apacheは/file.phpになります。

+1

YEEES、これが問題でした。それは今正しく動作します!感謝万円。 – BeeBee

関連する問題