Ad

Rewrite Rule Not Working In .htaccess

- 1 answer

I've the following .htaccess and I'm banally trying to do SEO rescripting of my site's url.

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]    

Everything works well, with the exclusion of the following url:

www.mysite.com/it/squadra/12345

With this, I've always 404 error, instead of the expected:

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

God, why?

Ad

Answer

Your problem seems to be due to option MultiViews.

Turn it off using this line on top of your .htaccess:

Options -MultiViews

Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs beforemod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.php.

Ad
source: stackoverflow.com
Ad