php – htaccess中主机名的重定向规则
发布时间:2020-12-13 22:26:20 所属栏目:PHP教程 来源:网络整理
导读:设,$staging_url = http://xx.xx.xx.xx/ $mobile_url = http://xx.xx.xx.xx/mobile/xxx/testing 我在我的htaccess文件中定义了这个重定向规则: RewriteCond "%{HTTP_USER_AGENT}" "(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera
设,$staging_url = http://xx.xx.xx.xx/
$mobile_url = http://xx.xx.xx.xx/mobile/xxx/testing 我在我的htaccess文件中定义了这个重定向规则: RewriteCond "%{HTTP_USER_AGENT}" "(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC] RewriteRule "/(.*)$" "/mobile/xxx/testing/$1" [L] 当我从手机上点击$staging_url时,它会重定向到$mobile_url.但是,当我点击$staging_url / design?id = 23时.它再次重定向到$mobile_url,我希望它重定向到$mobile_url / design?id = 23 提前致谢.我使用变量来定义我的链接,因为堆栈溢出只允许2个链接用于少于10个信誉的用户. RewriteEngine On Options FollowSymLinks RewriteBase / RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet) RewriteRule ^(.*)design$story.php?id=$1 [L,QSA] RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC] RewriteRule ^(.*)$http://google.com [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$/#/$1 [L] 解决方法
如
mod_rewrite docs中所述,您可以使用parantheses获取所请求URL的某些部分,并在以后引用它们,例如:
^/somepath(.*) /index.php?page=$1 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |