IP地址重定向到域名使用共享主机上的.htaccess
问题描述:
我想重定向我的IP地址到我的域名使用.htaccess文件,但它似乎并没有工作。除此之外,我还想将我的https链接重定向到http站点。任何人都可以帮忙IP地址重定向到域名使用共享主机上的.htaccess
我的.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>
答
你不能做到这一点的共享主机。共享主机的全部想法是,您共享同一台机器,并将其IP地址与多个其他网站共享。除非您的主机提供商允许您“声明”此IP地址(只有他们可以帮助您做),否则无法完成。如果可以这样做,那也意味着所有分享你IP的其他网站所有者可以做你正在做的事情。服务器在哪里重定向访问者呢?
因为这个原因,改变你的.htaccess文件根本无济于事。由托管提供商管理的服务器配置否决了这一点。某些托管服务提供商允许选择购买专用IP地址,或者通常如果您从其购买SSL证书,则会附带一个。除此之外,你没有选择。