【发布时间】:2010-11-18 09:23:11
【问题描述】:
首先我使用的是 Codeigniter 框架,所以这个问题是 CI 处理 URL 以及我使用 mod_rewrite 设置的当前重定向的一种解决方法。
我正在尝试获取像 /?gclid=somestringgoeshere 这样的 URL 以重定向到 /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 内部错误。
【问题讨论】:
标签: .htaccess mod-rewrite codeigniter redirect