如何在apache中使用正确的主机名请求时才允许访问?

时间:2014-08-18 07:56:01

标签: apache .htaccess virtualhost

我在230.230.230.230上运行了一个Web服务器。我的虚拟主机设置为ServerName mywebsite.comDocumentRoot /var/www/html/mywebsite.com/public

鉴于文件/var/www/html/mywebsite.com/public/index.html,我如何仅允许http://mywebsite.com/index.html但不允许http://230.230.230.230/mywebsite.com/public/index.html访问该文件?

我希望在.htaccess中放置/var/ww/mywebsite.com文件,将基于IP的/其他主机名流量重定向到正确的主机名。

修改:最后使用.htaccess

执行此操作
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mywebsite\.com$ [NC]
RewriteRule ^(.*)$ https://mywebsite.com/ [R=301,L]

0 个答案:

没有答案