0

我已经浏览了很多关于 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=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 ......它们总是为空......

4

1 回答 1

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 文件将其解析出来。

希望这可以帮助某人。

于 2013-06-26T19:00:04.667 回答