.htaccess not working only with internet explorer

本小妞迷上赌 提交于 2019-12-12 19:24:13

问题


i have site, that has to rewrite site.ru and www.site.ru to www,site.ru/ru_RU.

I can't access any Apache config files. In htaccess:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_HOST} ^site.ru$
RewriteRule (.*) http://www.site.ru/ru_RU [QSA]
RewriteCond %{HTTP_HOST} ^www.site.ru$
RewriteRule (.*) http://www.site.ru/ru_RU [QSA]

RewriteCond %{REQUEST_URI} ^/news
RewriteRule (.*) /news [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>

It's working in firefox or chrome, but in IE i get "this page can't be displayed". Tested on IE10 and IE8 (not compatibility view) on few computers.

If i write some junk in .htacess, i get 500 error in IE. Without .htaccess site loads ok, but i need it to rewrite url. Any ideas how to fix it?


回答1:


Your flags are all wrong. Modify your rules to this:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_HOST} ^site\.ru$ [NC]
RewriteRule ^ http://www.site.ru/ru_RU [L,R]

RewriteCond %{HTTP_HOST} ^www\.site\.ru$ [NC]
RewriteRule !ru_RU /ru_RU [NC,L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

</IfModule>

Reference: Apache mod_rewrite Introduction




回答2:


I can't test it now, but here is my guess: I think http_host ONLY contains the host part, not the uri. So you end up with an endless loop as www.site.ru is will always match again after your rewrite.

You will need another rule that checks if the uri is empty. Like this (untested):

RewriteCond %{REQUEST_URI} ^$
RewriteRule (.*) /ru_RU [QSA]

You might need another condition for the case that the uri contains a slash.



来源:https://stackoverflow.com/questions/19995747/htaccess-not-working-only-with-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!