使用用户代理的.htaccess URL重定向 [英] .htaccess URL redirection using User Agent

查看:106
本文介绍了使用用户代理的.htaccess URL重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找到一个解决方案,我的情况,但没有奏效。我有一个做了以下以下htaccess文件:

I've been trying to find a solution to my situation but none worked. I have the following htaccess file which does the following:

  1. 重定向 site.com/m/page site.com/m/#page

我重定向 site.com/d/page site.com/m/#page

它删除的.php 扩展和通用_ 的模式,我曾在页面的前面

It deletes .php extension and the common_ pattern which I had in front of the pages

在code到目前为止:

The code so far:

Options +FollowSymlinks -MultiViews

RewriteEngine On    
RewriteBase /

RewriteRule ^[dm]/(.+)$ /m/#$1 [R=302,NE,L,NC]

## hide .php extension
RewriteCond %{THE_REQUEST} \s/+common_([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,L,NE]

## To internally forward
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/common_$1.php -f
RewriteRule ^(.+?)/?$ common_$1.php [L]

我想了如下因素:

I would like the folowing:

a)如果某个用户从iPhone进入 site.com/m /...,继续(什么都不做)

a) If some user enters from an iPhone 'site.com/m/...' , continue (do nothing)

二)如果有些用户从AR的iPad桌面进入 site.com/m/page 重定向他 site.com/d/#page

b) If some user enters from a desktop ar iPad 'site.com/m/page' to redirect him to 'site.com/d/#page'

我真的AP preciate一些帮助。

I would really appreciate some help.

推荐答案

您可以使用一个新的规则如下:

You can use a new rule for this:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} !iphone [NC]
RewriteRule ^m/(.+)$ /d/#$1 [R=302,NE,L,NC]

RewriteRule ^[dm]/(.+)$ /m/#$1 [R=302,NE,L,NC]

## hide .php extension
RewriteCond %{THE_REQUEST} \s/+common_([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,L,NE]

## To internally forward
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/common_$1.php -f
RewriteRule ^(.+?)/?$ common_$1.php [L]

这篇关于使用用户代理的.htaccess URL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆