.htaccess重定向错误

问题描述:

首先我正在使用Codeigniter框架,所以这个问题是一个解决方法CI处理URL以及我使用mod_rewrite设置的当前重定向的方式。.htaccess重定向错误

我正在尝试获得像这样的网址/?gclid=somestringgoeshere重定向到/index.php?/home/gclid/somestringgoeshere

目前的.htaccess我已经设置低于

<IfModule mod_rewrite.c> 
    Options +FollowSymlinks 
    RewriteEngine On 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 


    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6_$7 [L] 
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5_$6 [L] 
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4_$5 [L] 
    RewriteRule ^([^_]+)-([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3_$4 [L] 
    RewriteRule ^([^_]+)-([^_]+)-([^.]+)$ index.php?/$1_$2_$3 [L] 
    RewriteRule ^([^_]+)-([^.]+)$ index.php?/$1_$2 [L] 

    # Checks to see if the user is attempting to access a valid file, 
    # such as an image or css document, if this isn't true it sends the 
    # request to index.php 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # This last condition enables access to the images and css folders, and the robots.txt file 
    # Submitted by Michael Radlmaier (mradlmaier) 

    RewriteCond $1 !^(index\.php|images|robots\.txt|css) 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

我试图使用权上面的第一个成立了重写条件和规则的下面的代码赶上它,它尝试的其他任何操作之前

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

RewriteRule ^\?gclid=(.*)$ index.php?/home/gclid/$1 [L] 

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

所有要么不显示正确的页面或想出500内部错误。

的URI的查询只能用RewriteCond directive进行测试:

RewriteCond %{QUERY_STRING} ^gclid=(.*) 
RewriteRule ^$ index.php?/home/gclid/%1 [L] 

或者更一般的(将考虑进一步的查询参数):

RewriteCond %{QUERY_STRING} ^([^&]*&)*gclid=([^&]*) 
RewriteRule ^$ index.php?/home/gclid/%2 [L] 

哦,顺便说一句:RewriteCond指令只能对应到第一个以下RewriteRule指令。

+0

它需要?在像这样的网址中^?gclid =(。*)但是也显示错误 – cointilt 2009-08-10 19:30:54

+0

您只能用'RewriteRule'指令测试URI路径。 URI查询(从第一个“?”到之后的第一个“#”的部分)只能用'%{QUERY_STRING}'变量访问。这只能通过'RewriteCond'指令来实现。所以我的例子应该工作。 – Gumbo 2009-08-10 19:52:21

+0

发现有一些问题,我从你的例子中复制的文本,它插入了一个奇怪的字符。谢谢! – cointilt 2009-08-10 20:15:25