首先我正在使用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内部错误。
答案 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
指令。