用户代理的 mod_rewrite 不起作用?

发布于 2024-12-28 09:59:38 字数 375 浏览 3 评论 0原文

我想实现以下目标,如果有人使用 Android/iPhone 用户代理进入网站,我想将他的所有 url 重写到一个目录,例如:

user enters -> user served
example.com -> example.com/mobile
example.com/review/12 -> example.com/mobile/review/12

我的 .htaccess 中有以下示例代码片段,但它不起作用。 ..

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} Android
RewriteRule ^(.*)/$ mobile/$1

I want to achieve the following, if someone enters site with Android/iPhone user agent, I want to rewrite all his urls to a directory, so for example:

user enters -> user served
example.com -> example.com/mobile
example.com/review/12 -> example.com/mobile/review/12

I have the following example code snippet in my .htaccess, but it's not working...

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} Android
RewriteRule ^(.*)/$ mobile/$1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2025-01-04 09:59:38

尝试将以下内容添加到站点根目录中的 htaccess 文件中。

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} Android [NC]
RewriteCond %{REQUEST_URI} !^/mobile [NC]
RewriteRule ^(.*)/?$ mobile/$1 [L]

如果您想更改用户在浏览器地址栏中看到的内容,请将最后一行更改为

RewriteRule ^(.*)/?$ mobile/$1 [L,R]

Try adding the following to your htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} Android [NC]
RewriteCond %{REQUEST_URI} !^/mobile [NC]
RewriteRule ^(.*)/?$ mobile/$1 [L]

If you want to change what the user sees in their browser address bar, change the last line to

RewriteRule ^(.*)/?$ mobile/$1 [L,R]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文