2012-12-03 54 views
0

我想
www.example.com/tops/articles/first_article
重定向地址到地址
www.example.com/tops/test1.php?name = first_article.htaccess的目录重定向


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 

Doe的任何人有任何想法为什么是这样的? 我在做什么错?

在此先感谢。

+0

几乎所有的东西。 –

+0

请告诉我什么是缺失的,所以我会知道下一次。 –

+0

特别是模式'/ tops' –

回答

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中移除。

+0

中第一个子目录的第一个斜杠不符合我的要求。 –

+0

这是你的要求! –

+0

问题是我没有详细说明我的要求。 它需要引用所有的文字,而不仅仅是您提供的文字。 我不得不提到的另一件事是,htaccess文件位于http://www.example.com/tops –

0

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

如果不是,那么这可能是你的问题。你应该改变你的最后一条规则,如:

RewriteRule ^tops/(.*)$ /tops/page.php?name=$1 
+0

第三条规则完美运作。我没有问题。问题在于第一条和第二条规则。 –

+0

@Amit Aisikowitz你可以不用斜线来尝试:'^ tops /'而不是'^/tops /'。 – jeroen

0

嗯,我终于得到它的工作。

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

这里是workd代码:

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] 

享受!