.htaccess问题中的mod_rewrite

时间:2013-06-26 02:42:35

标签: mod-rewrite

我已经嗅了很多关于mod_rewrite的帖子,结果比我想象的要复杂得多。

我要做的是以下内容。 我有10个城市有活动,每个城市应该有自己的“目录”,例如: site.com/toronto/ site.com/chicago /

事件最多可包含3个子级别,例如

site.com/toronto/musiccamp/sub18

site.com/chicago/bootcamp

我需要将这些网址映射到网页

site.com/camps/index.php?city=toronto&type=musiccamp&ages=sub18

site.com/camps/index.php?city=chicago&type=bootcamp

其他目录,例如 site.com/about - site.com/help等 不应该改写。

这必须在.htaccess文件中。

到目前为止,我得到了这个(在godaddy服务器中)

#Fix Rewrite
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php?option1=$1 [L]

但是我无法将选项传递给index.php ......它们总是为空...

1 个答案:

答案 0 :(得分:1)

最后,这是我个案中最有效的方法

#Fix Rewrite
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php?option1=%{REQUEST_URI}

这样,任何不存在的路径都会被重写到/test/index.php文件,并可以从那里处理。

传递REQUEST_URI允许我深度构建N级并让index.php文件解析出来。

希望这有助于某人。

相关问题