Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的重定向Url_Php_.htaccess_Codeigniter_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php codeigniter中的重定向Url

Php codeigniter中的重定向Url,php,.htaccess,codeigniter,mod-rewrite,url-rewriting,Php,.htaccess,Codeigniter,Mod Rewrite,Url Rewriting,我想在我的lcalhost中重定向一个url,就像用户键入:mystring.localhost/CI到codeigniter中的localhost/CI/Mycontroller/Myaction/mystring一样。它现在显示找不到服务器,并显示浏览器Firefox在www.mystring.localhost上找不到服务器。如何做到这一点?提前谢谢。我的.htaccess中有这个: RewriteEngine On RewriteCond %{HTTP_HOST

我想在我的lcalhost中重定向一个url,就像用户键入:
mystring.localhost/CI
到codeigniter中的
localhost/CI/Mycontroller/Myaction/mystring
一样。它现在显示找不到服务器,并显示浏览器Firefox在
www.mystring.localhost
上找不到服务器。如何做到这一点?提前谢谢。我的
.htaccess
中有这个:

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

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

127.0.0.1 mystring.localhost
因此,它将把所有请求从
mystring.localhost
重定向到
127.0.0.1

Linux上的语法相同,但文件位于
/etc/hosts


然后,您必须使用Apache配置上的
RewriteCond
.htaccess

创建一些
别名
重写规则
,因此如果我理解正确:

-有人会键入mystring.localhost/CI,您希望它将他们重定向到具有操作和值的特定页面吗

如果是这样,您可以在\application\config\config.php中将页面设置为索引页面

其第30行:

$config['index_page'] = 'Mycontroller/Myaction/mystring';
否则,在处理索引的控制器中,只需在其_构造函数中执行重定向

很可能有一个解决方案涉及HTACCESS文件,但我对此不是很了解

希望这有帮助


-Gui

添加到c:\wamp\bin\apache\ApacheYOUVERSION\conf\extra\httpd-vhosts.conf

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

我在我的.htaccess:RewriteEngine On RewriteCond%{HTTP_HOST}^string\.localhost\Tests\RewriteRule^(.*)$[R=301]中有这个,但它似乎不起作用。不幸的是,这在localhost中不起作用,所以我在托管站点中尝试了,但它似乎也不起作用。不,这里“mystring”是一个变量,我必须在我的控制器中捕捉这个字符串以重用它,这就是我的意思。它不会每次都是“mystring”。抱歉,但在windows中不可能有本机子域,看起来没问题,我想它可以使用。htaccess:现在我尝试了以下方法:RewriteCond%{HTTP_HOST}^([a-z0-9-]+).localhost/Tests[NC]RewriteRule([a-z0-9-]/?)(*)index.php/$1/%1/$2[QSA],但是它现在不工作了,它重定向到本地主机本身,我希望它转到一个特定的控制器和操作。我可以将“mystring”作为变量吗?您需要在Apache上的
.htaccess
VirtualHost
中配置它。我正在寻找.htaccess,没关系,我认为很遗憾,这在本地主机中不起作用,所以我在托管站点中尝试过,但它似乎也不起作用。如何将其与.htaccess一起使用?我现在陷入困境
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).yourdomain.dev [NC]  
RewriteRule ([a-z0-9-]+)(/+.*) index.php/$1/%1$2 [QSA]