mod_rewrite in .htaccess issues



我浏览了很多关于mod_rewrite的帖子,结果发现这比我预期的更复杂。

我想做的是以下几点。我有10个城市举办活动,每个城市都应该有自己的"目录",例如:site.com/toronto/site.com/chicago/

事件可能有多达3个子级别,如

site.com/toronto/musiccamp/sub18

site.com/chicago/bootcamp

我需要这些URL映射到页面

site.com/camps/index.php?city=多伦多&type=musiccamp&年龄=18岁以下

site.com/camps/index.php?city=芝加哥&type=训练营

其他目录,例如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…它们总是空的。。。

最后,这是在我的案例中效果最好的

#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文件解析它。

希望这能帮助到别人。

最新更新