我已经尝试了所有可能的配置,但我就是无法使其工作。我知道这个话题已经出现了很多次,但我无法为我的情况找到正确的解决方案,尽管它应该很简单。
访问www.example.fr
时,一切正常,我被重定向到 https://www.example.fr。
现在,如果我访问example.fr
,则我会被重定向到 https://www.example.fr/index.php。
我还注意到,如果我访问 https://www.example.com(相同的域,属于我的不同扩展名(,我会被重定向到 https://www.example.com/index.php
这是我的.htaccess。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [L,QSA]
RewriteCond %{HTTP_HOST} ^example.fr [NC]
RewriteRule ^(.*)$ http://www.example.fr/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
我想永远摆脱这种/index.php
。任何帮助将不胜感激!
您必须在重写之前放置重定向:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web/
RewriteCond %{HTTP_HOST} ^example.fr [NC]
RewriteRule ^ https://www.example.fr%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L,QSA]
</IfModule>