简体   繁体   English

htaccess基于IP或域的重写

[英]htaccess rewrite based on IP or domain

I'm using Codeigniter, now the rewrite is working fine for accessing using domain name, here is the default Codeigniter htaccess: 我正在使用Codeigniter,现在重写工作正常,可以使用域名进行访问,这是默认的Codeigniter htaccess:

RewriteRule ^(.*)$ index.php?/$1 [L]

But I want to make it able to access using IP address as well and I host my website in a shared hosting with cPanel, so the IP address will be something like this: http://11.11.11.11/~username . 但是我也想使其能够使用IP地址进行访问,并且将我的网站托管在与cPanel共享的主机中,因此IP地址将是这样的: http://11.11.11.11/~username : http://11.11.11.11/~username But it just not working when I access using IP, I had tried adding a RewriteBase and also something like: 但是当我使用IP访问时,它只是不起作用,我曾尝试添加RewriteBase以及类似的东西:

RewriteRule ^(.*)$ ~username/index.php?/$1 [L]

and

RewriteRule ^~username/(.*)$ index.php?/$1 [L]

but non of them work. 但它们都不起作用。 Anyone please help? 有人帮忙吗? Thank you. 谢谢。

Ok I just found the solution, I should check the host so that RewriteBase only will work properly: 好的,我刚刚找到了解决方案,我应该检查主机,以便仅RewriteBase可以正常工作:

RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteBase /~username/
RewriteCond %{HTTP_HOST} ^11\.11\.11\.11 [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]

Ping, 平,

Unfortunately, you can not use IP as host while you'r on shared hosting. 不幸的是,当您使用共享主机时,不能将IP用作主机。 Share hosting shared single IP for multiple websites. 共享托管多个网站共享的单个IP。

You need dedicated hosting or VPS for your purpose. 您需要专用的托管或VPS。

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

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