0

我正在尝试将地址 www.example.com/tops/articles/first_article 重定向

地址
www.example.com/tops/test1.php?name=first_article

还将地址 www.example.com/tops/galleries/first_gallery 重定向

地址
www.example.com/tops/test2.php?name=first_gallery

以及所有其他地址,例如
www.example.com/tops/first_page

www.example.com/tops/page.php?name=first_page

以下 htaccess 文件给了我一个重定向循环。

RewriteEngine on
Options +FollowSymLinks

RewriteRule ^/tops/articles/(.+)$  /tops/test1.php?name=$1  [L]

RewriteRule ^/tops/galleries/(.+)$  /tops/test2.php?name=$1  [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)$ ./page.php?name=$1

有人知道这是为什么吗?我究竟做错了什么?

提前致谢。

4

3 回答 3

0

是否page.php存在于根目录(或任何其他非/tops/目录)中?

如果没有,那么这可能是你的问题。您应该将最后一条规则更改为:

RewriteRule ^tops/(.*)$ /tops/page.php?name=$1
于 2012-12-03T15:34:19.540 回答
0

你可以试试这个:

RewriteEngine On
RewriteRule ^tops/articles/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/tops/test1.php?name=$1 [L]
RewriteRule ^tops/galleries/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/tops/test2.php?name=$1 [L]
RewriteRule ^tops/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/page.php?name=$1 [L]

用这些规则替换所有 3 条规则。

更新所有字符:

RewriteEngine On
RewriteRule ^tops/articles/([^/]*)/?$   http://www.example.com/tops/test1.php?name=$1 [L]
RewriteRule ^tops/galleries/([^/]*)/?$   http://www.example.com/tops/test2.php?name=$1 [L]
RewriteRule ^tops/([^/]*)/?$   http://www.example.com/tops/page.php?name=$1 [L]

.htaccess 应该在根目录中 如果它在/tops目录中,请尝试将其从模式和替换 URL 中删除。

于 2012-12-03T15:29:12.603 回答
0

好吧,我终于让它工作了。

以为我分享它,所以如果有人每次搜索这个问题,他都会找到它。

这是有效的代码:

RewriteEngine on
Options +FollowSymLinks

RewriteRule ^articles/(.+)$ ./test1.php?name=$1 [L]

RewriteRule ^galleries/(.+)$ ./test2.php?name=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)$ ./page.php?name=$1 [L]

享受 !

于 2012-12-04T03:34:13.767 回答