Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Mod Rewrite路由/加载所有文件(如果条件正确)_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache Mod Rewrite路由/加载所有文件(如果条件正确)

Apache Mod Rewrite路由/加载所有文件(如果条件正确),apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我想要实现的是为使用htaccess contidion的移动用户从子文件夹加载静态文件 如果user_agent=mobile,则加载/mob/*.html,否则加载*.html RewriteEngine On RewriteBase / RewriteCond %{HTTP_USER_AGENT}(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|... (list is very lon

我想要实现的是为使用htaccess contidion的移动用户从子文件夹加载静态文件

如果user_agent=mobile,则加载/mob/*.html,否则加载*.html

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT}(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|... (list is very long)
RewriteRule ^$ /mobile/$ [R,L]
另外,我还研究了ApacheAMF,但它们有重定向到m.domain.com的示例,而我希望从子文件夹加载静态文件。顺便说一下,我不想在地址栏中显示/mobile/。我也想阻止对/mobile/*.html文件的直接访问


您需要在
重写规则
中捕获值,并将其用作反向引用:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT}(android|bb\d+|meego).+(mobile|avantgo|bada/|blackberry|blazer|compal|elaine)
RewriteRule ^((?!mobile/).*)$ mobile/$1 [L,NC]

不要在规则中使用显式
R
标志,它会进行外部重定向,因此会更改浏览器中显示的URL。我收到内部服务器错误500。这都是我的权限。我还有其他错误吗?选项+以下链接RewriteBase/RewriteCond%{HTTP_HOST}domain\.com\.au$RewriteCond%{HTTP_USER_AGENT}(android | bb\d+| meego)。+mobile | avantgo | bada\/| blackberry | blazer | compal | elaine | fennec | hiptop。。etc)[NC]RewriteRule^(.*)$mobile/$1[L]现在它可以用于域根,我的意思是.com.au/,但不能用于.com.au/test.html。这次没有错误,但它在/*.htmlNo上加载了desktrop版本,这是不对的。在我的Apache上,它在
domain.com.au/test.html
alsoIt是Apache2.4,Centos7x64上运行良好。我将在另一台服务器上检查。我在该框中检查了apache配置,似乎我在该服务器上添加了一些额外的行来解决一些htaccess设置。现在问题解决了。非常感谢你!