【问题标题】:htaccess : access non www domain is showing index.php in urlhtaccess :访问非 www 域在 url 中显示 index.php
【发布时间】:2018-01-10 23:00:59
【问题描述】:

我已经尝试了所有可能的配置,但我无法使其正常工作。 我知道这个话题已经出现了很多次,但我无法为我的案例找到正确的解决方案,尽管它应该很简单。

访问www.example.fr 时,一切正常,我被重定向到https://www.example.fr

现在,如果我访问example.fr,那么我会被重定向到https://www.example.fr/index.php
我还刚刚注意到,如果我访问https://www.example.com(同一个域,属于我的不同扩展名),我会被重定向到@987654324 @

这是我的 .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。 任何帮助将不胜感激!

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    您必须在重写之前放置重定向:

    <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>
    

    【讨论】:

    • 哦,谢谢,通知没有出现,我会尝试告诉你,但我终于设法找到了出路!
    • 谢谢,我又回到了这个问题,我不得不解决一些其他问题,但现在一切都很好,感谢您提醒我正确的顺序。我可能还有一个问题,关于重定向,稍后我可能会联系你!
    • 哦,顺便说一句,我让它工作了,但我忘了告诉你一件事:如果 'index.php' 在 URL 中(比如,如果我手动添加它)它不会被删除(但我所有的重定向都工作正常)。这是预期的行为吗?我非常担心重定向,以至于我忘记了主要部分啊哈。因此,正如我在第一条评论中所说,我设法通过添加来摆脱它: RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L] 否则它仍然在这里......我现在迷路了啊哈!
    • 是的,你必须这样做才能摆脱 index.php
    猜你喜欢
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2017-09-14
    • 2016-03-17
    • 1970-01-01
    • 2019-08-12
    • 2012-10-17
    相关资源
    最近更新 更多