【问题标题】:Forbid access to website through IP server禁止通过IP服务器访问网站
【发布时间】:2017-04-11 09:45:31
【问题描述】:

我在我的 Debian 服务器上托管我的网站。我的网站可以通过域名https://www.domainname.fr访问

但是没有什么能阻止用户通过服务器的IP/myhostname访问网站,所以http://serveripadress/domainname/

我放了一个

Options All -Indexes

在.htaccess 中禁止访问网站存储库,但我不希望用户通过http://serveripadress/domainname/ url 在网站上导航...

我需要自动将人们从http://serveripadress/domainname/重定向到真实域名https://www.domainname.fr

我该怎么做? .htaccess 是否有其他类型的访问保护?

这是我当前的 .htaccess 内容:

#FallbackResource /index.php

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# Désactiver l'exploration des répertoires web
Options All -Indexes

感谢您的帮助

【问题讨论】:

    标签: linux apache .htaccess mod-rewrite debian


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此规则:

    Options All -Indexes
    RewriteEngine On
    RewriteBase /
    
    # if hostname in current request is not www.domainname.fr
    RewriteCond %{HTTP_HOST} !^(?:www\.)?domainname\.fr$ [NC]
    # then redirect
    RewriteRule ^ http://www.domainname.fr%{REQUEST_URI} [L,NE,R=301]
    
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

    • 感谢@anubhava,但我的.htaccess 不是空的(我编辑了我的帖子),那么我该如何调整它呢?
    • 在RewriteEngine On 行下方插入我建议的规则。根据我编辑的答案。
    猜你喜欢
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    相关资源
    最近更新 更多