2016-12-13 123 views
0

我的.htaccess文件出现问题。 一切工作正常,直到我做了一些改变(增加了多语言处理):页面没有正确重定向 - .htaccess文件问题

前:

RewriteEngine On 

RewriteBase/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
RewriteRule ^(index.html)$ http://my-site.pl/ [R=301,L] 

我在文件末尾添加:

RewriteCond %{HTTP:Accept-Language} (pl) [NC] 
RewriteRule .* index.html [R,L] 
RewriteCond %{HTTP:Accept-Language} (en) [NC] 
RewriteRule .* index.en.html [R,L] 
RewriteCond %{HTTP:Accept-Language} (jp) [NC] 
RewriteRule .* index.jp.html [R,L] 

我想将所有国家重定向到他们的页面,仅在我的页面URL中更改(..):http://my-site.pl/index.(..).html,如上面的代码所示。

我找不到问题在哪里。从Firefox浏览器

错误:

的网页没有正确重定向。 Firefox检测到 服务器正在重定向该地址的请求,其方式 从未完成。

编辑:被重定向到index.html/从而导致重定向循环

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule^http://%1%{REQUEST_URI} [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /index\.html [NC] 
RewriteRule ^index\.html$/[R=301,L,NC] 

RewriteCond %{HTTP:Accept-Language} pl [NC] 
RewriteRule ^(?!index\.html$).+$/[NC,R,L] 

RewriteCond %{HTTP:Accept-Language} en [NC] 
RewriteRule ^/?$ index.en.html [R,L] 

RewriteCond %{HTTP:Accept-Language} jp [NC] 
RewriteRule ^/?$ index.jp.html [R,L] 

ErrorDocument 404 /404.html 

## EXPIRES CACHING ## 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType image/jpg "access 1 year" 
ExpiresByType image/jpeg "access 1 year" 
ExpiresByType image/gif "access 1 year" 
ExpiresByType image/png "access 1 year" 
ExpiresByType text/css "access 1 month" 
ExpiresByType text/html "access 1 month" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
ExpiresByType image/x-icon "access 1 year" 
ExpiresDefault "access 1 month" 
</IfModule> 
## EXPIRES CACHING ## 
<IfModule mod_deflate.c> 
    # Compress HTML, CSS, JavaScript, Text, XML and fonts 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE application/rss+xml 
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font 
    AddOutputFilterByType DEFLATE application/x-font-opentype 
    AddOutputFilterByType DEFLATE application/x-font-otf 
    AddOutputFilterByType DEFLATE application/x-font-truetype 
    AddOutputFilterByType DEFLATE application/x-font-ttf 
    AddOutputFilterByType DEFLATE application/x-javascript 
    AddOutputFilterByType DEFLATE application/xhtml+xml 
    AddOutputFilterByType DEFLATE application/xml 
    AddOutputFilterByType DEFLATE font/opentype 
    AddOutputFilterByType DEFLATE font/otf 
    AddOutputFilterByType DEFLATE font/ttf 
    AddOutputFilterByType DEFLATE image/svg+xml 
    AddOutputFilterByType DEFLATE image/x-icon 
    AddOutputFilterByType DEFLATE text/css 
    AddOutputFilterByType DEFLATE text/html 
    AddOutputFilterByType DEFLATE text/javascript 
    AddOutputFilterByType DEFLATE text/plain 
    AddOutputFilterByType DEFLATE text/xml 

    # Remove browser bugs (only needed for really old browsers) 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 
    BrowserMatch ^Mozilla/4\.0[678] no-gzip 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
    Header append Vary User-Agent 
</IfModule> 

回答

0

问题是在被重定向到index.html和2章第3条: 更改后(还是不行)充分的.htaccess 。

有这样说:

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule^http://%1%{REQUEST_URI} [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /index\.html [NC] 
RewriteRule ^index\.html$/[R=301,L,NC] 

RewriteCond %{HTTP:Accept-Language} pl [NC] 
RewriteRule ^(?!index\.html$).+$/[NC,R,L] 

RewriteCond %{HTTP:Accept-Language} en [NC] 
RewriteRule ^/?$ index.en.html [R,L] 

RewriteCond %{HTTP:Accept-Language} jp [NC] 
RewriteRule ^/?$ index.jp.html [R,L] 

确保清除浏览器缓存,同时测试。

+0

不幸的是仍然无法正常工作......同样的错误......每次清除缓存时 – Krzysiek

+0

仍然可以看到相同的错误。在Firefox和移动电话上的Internet Explorer上测试 – Krzysiek

+0

pl重定向规则有问题。没有这个,一切正常,但不幸的是,所有页面都被重定向到en – Krzysiek