0

我有这个重写代码:

RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://stagingsite.com/site/mobile [R=301]
RewriteRule ^faq/$ /mobile/faq

第一行工作正常。如果用户使用的是 iphone,则重定向到显示索引页面的移动目录。

我还希望用户访问:

http://stagingsite.com/site/faq

如果他们在 iphone 上,则转发到http://stagingsite.com/site/mobile/faq但上面的最后一行代码似乎没有实现这一点。

有什么想法我错了吗?

4

2 回答 2

1

RewriteCond directives only get applied to the *immediately following RewriteRule. So you have the condition that checks for iPhone, but that only gets applied to the redirect rule, and not the faq rule. You have to duplicate it:

RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://stagingsite.com/site/mobile [R=301,L]

RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^faq/?$ /site/mobile/faq [L]

You should also include L flags so the 2 rules don't accidentally interfere with each other. And your regex and target needs to be updated to accept an optional trailing slash and the subdirectory.

于 2012-10-02T17:12:24.737 回答
0

在移动之前取出斜线作为

RewriteRule ^faq/$ mobile/faq 

作品?

于 2012-10-02T13:58:41.580 回答