我正在尝试使用 .htaccess 文件将我的 IP 地址重定向到我的域名,但它似乎不起作用。除此之外,我还想将我的https链接重定向到http站点。谁能帮忙.
我的.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 证书,它会附带一个。除此之外,您没有选择。