.htaccess重定向错误

时间:2009-08-10 18:26:17

标签: .htaccess mod-rewrite codeigniter redirect

首先我正在使用Codeigniter Framework,因此这个问题是CI处理URL以及我使用mod_rewrite设置的当前重定向的方式。

我正在尝试将此/?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内部错误。

1 个答案:

答案 0 :(得分:2)

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指令。