简体   繁体   English

在共享主机上使用.htaccess将IP地址重定向到域名

[英]Ip address redirect to Domain name using .htaccess on shared hosting

I am trying to redirect my IP address to my domain name using .htaccess file but it doesn't seems to be working . 我正在尝试使用.htaccess文件将我的IP地址重定向到我的域名,但它似乎无法正常工作。 Along with this i would like to redirect my https link to http site as well. 与此同时,我也想将https链接也重定向到http站点。 Can anyone help . 谁能帮忙。

my .htaccess file looks like this 我的.htaccess文件看起来像这样


Options -Indexes

ErrorDocument 404 /404.php
ErrorDocument 403 /

<FilesMatch "\.inc.php">
  order deny,allow
  deny from all
</FilesMatch>

## SEO Friendly URLs ##
RewriteEngine On

RewriteCond %{HTTP_HOST} ^111\.11\.111\.11$
RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]


RewriteRule ^(admin)($|/) - [L]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]


RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

<IfModule mod_expires.c>
    ExpiresActive on

    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
</IfModule>

You cannot do this on shared hosting. 您不能在共享主机上执行此操作。 The whole idea of shared hosting is that you share the same machine and it's IP address(es) with multiple other websites. 共享主机的整个想法是,您与多个其他网站共享同一台计算机及其IP地址。 Unless your hosting provider allows you to "claim" this IP address (which only they can help you do), it cannot be done. 除非您的托管服务提供商允许您“声明”该IP地址(只有他们可以帮助您这样做),否则您将无法做到这一点。 If it could be done, that would also mean that all the other website owners that share your IP could do what you are doing. 如果可以做到,那也意味着共享您IP的所有其他网站所有者都可以做您正在做的事情。 Where is the server going to redirect the visitor then? 服务器将重定向到哪里?

Because of this reason, changing your .htaccess file won't help anything at all. 因此,更改.htaccess文件根本无济于事。 The server configuration that is managed by your hosting provider overrules this. 由托管服务提供商管理的服务器配置对此无效。 Some hosting providers allow the option to buy a dedicated IP address or usually if you buy an SSL certificate from them it comes with one. 一些托管服务提供商允许选择购买专用IP地址,或者通常,如果您从他们那里购买SSL证书,则它附带一个。 Other than that, there are no options you have. 除此之外,您没有其他选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM