htacces无法删除index.php完全离开/?在网址中

时间:2015-08-31 08:22:05

标签: apache .htaccess mod-rewrite

我的网站完全https,但我无法从/index.php?/移除urls

当我尝试打开网站时:example.com/links页面重定向到https://example.com/?/links我似乎无法移除/?部分。我尝试了很多不同的方法,但我不是htaccess / regex英雄。这是我最接近正确的方法。一些帮助将不胜感激。

RewriteEngine on
RewriteRule cache/ - [F]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_URI} !=/favicon.ico

2 个答案:

答案 0 :(得分:1)

重新排列您的规则:

RewriteEngine on
RewriteBase /

RewriteRule cache/ - [F]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

请务必在清除浏览器缓存后对其进行测试。

答案 1 :(得分:0)

Fist重定向到https(R = 302 = temp,R = 301 =永久)并停止检查其他规则(L),然后删除index.php。否则,它会重定向到该网址,以便当时看到它。

RewriteEngine on
RewriteBase /
RewriteRule cache/ - [F]

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_URI} !=/favicon.ico