2013-05-06 57 views
0

我想在我的lcalhost中重定向url,因为当用户输入:mystring.localhost/CIlocalhost/CI/Mycontroller/Myaction/mystring in codeigniter。现在显示Server not found并且表示浏览器Firefox无法在www.mystring.localhost找到服务器。这个怎么做 ?提前致谢。我有这个在我的.htaccess在codeigniter中重定向Url

RewriteEngine On  
    RewriteCond %{HTTP_HOST} ^mystring\.localhost\CI\ 
    RewriteRule ^(.*)$ http://localhost/CI/Mycontroller/myaction/mystring/$1 [R=301] 
+0

你试过了。 – 2013-05-06 13:01:13

+0

我在.htaccess中有这个:RewriteEngine On RewriteCond%{HTTP_HOST}^string \ .localhost \ Tests \ RewriteRule ^(。*)$ http:// localhost/Tests/string/$ 1 [R = 301],但它似乎不工作。 – Crazyrubixfan 2013-05-06 13:05:38

+0

不幸的是,这是不是在localhost工作,所以我尝试在一个托管的网站,但它似乎也不工作 – Crazyrubixfan 2013-05-06 14:24:00

回答

1

在Windows上编辑文件C:\Windows\System32\drivers\etc\hosts然后追加:

127.0.0.1 mystring.localhost 

那么它将从mystring.localhost所有请求重定向到127.0.0.1

在Linux上是相同的但文件是/etc/hosts

然后,你必须做一些AliasRewriteRuleRewriteCond在Apache配置或.htaccess

+0

让我锻炼这个,谢谢 – Crazyrubixfan 2013-05-06 13:06:44

+0

现在它重定向到localhost本身,我希望它去一个特定的控制器和行动。我可以将“mystring”作为变量吗? – Crazyrubixfan 2013-05-06 13:25:37

+0

您需要在Apache上的'.htaccess'或'VirtualHost'上进行配置。 – 2013-05-06 13:31:53

-1

所以,如果我理解正确的话:

-Someone就打入mystring.localhost/CI,以及你希望它重定向到某个页面的动作和价值?

如果是这样,你可以设置一个网页,如\应用程序的索引页\ CONFIG \ config.php文件

其上线30:

$config['index_page'] = 'Mycontroller/Myaction/mystring'; 

否则在刚刚处理索引控制器在它的__construct函数中做一个重定向。

最有可能的解决方案涉及HTACCESS文件,但我不是很了解这方面的知识。

希望这会有所帮助!

-gui

0

添加到c:\ WAMP \ BIN \ apache的\ ApacheYOUVERSION \的conf \额外\的httpd-vhosts.conf

NameVirtualHost *.yourdomain.dev 
<VirtualHost *:80> 
    DocumentRoot "c:/wamp/www/CI" 
    ServerName *.yourdomain.dev 
</VirtualHost> 

查找#Include conf/extra/httpd-vhosts.confc:\wamp\bin\apache\ApacheYOUVERSION\conf\httpd.conf,在开始处

删除 #

hosts文件:127.0.0.1 yourdomain.dev

广告d这对你的htaccess:

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).yourdomain.dev [NC] 
RewriteRule ([a-z0-9-]+)(/+.*) index.php/$1/%1$2 [QSA] 
+0

没有在这里“MyString的”是一个变量在这里,我必须抓住这个字符串在我的控制器重用,那是什么我的意思是 。它不会每次都是“mystring”。 – Crazyrubixfan 2013-05-06 13:22:13

+0

我刚刚意识到,等待.. – Aurel 2013-05-06 13:24:36

+0

尝试使用'mystring.yourdomain.dev'进行最后一次编辑 – Aurel 2013-05-06 13:41:04