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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
.htaccess htaccess:模拟URL上的切换情况,尤其是';默认值';_.htaccess_Url - Fatal编程技术网

.htaccess htaccess:模拟URL上的切换情况,尤其是';默认值';

.htaccess htaccess:模拟URL上的切换情况,尤其是';默认值';,.htaccess,url,.htaccess,Url,我有一个网站,我必须重写与htaccess网址。有没有办法像处理开关的case语句一样处理这个问题 假设我的网站是foobar.com,我想要 foobar.com/red=>foobar.com/republican.php foobar.com/blue=>foobar.com/democratir.php foobar.com/green/xyz=>foobar.com/green.php?id=xyz 默认值: foobar.com/*=>foobar.com/page.php?查询=*

我有一个网站,我必须重写与htaccess网址。有没有办法像处理开关的case语句一样处理这个问题

假设我的网站是foobar.com,我想要

foobar.com/red=>foobar.com/republican.php

foobar.com/blue=>foobar.com/democratir.php

foobar.com/green/xyz=>foobar.com/green.php?id=xyz

默认值:

foobar.com/*=>foobar.com/page.php?查询=*

目前,这是我的设置:

RewriteRule ^/red foobar.com/republican.php [works fine]

RewriteRule ^/blue foobar.com/democrat.php [works ok]

RewriteRule ^green/([^/.]+)/?$ green.php?id=$1
[error: redirect loop with foobar.com/green/home.php in browser address because green.php without id set redirects to home.php]

default [no idea how to implement]

找到了这样做的方法:

请参见上的“使用路由文件”