使用.htaccess文件,我希望将平板电脑流量重定向到平板电脑优化网站。
常规网址:waxxxed.com.au 平板电脑优化网址:waxxxed.com.au/tablet /
我尝试了以下代码,但它不起作用。
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteCond %{HTTP_HOST} !^ipad\. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
x3问题......
全电流.htaccess文件(有效!)......
<IfModule mod_expires.c>
# Enable cache expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
</IfModule>
# force redirect of html to no-extension
RewriteCond %{THE_REQUEST} ^GET\s.+\.html
RewriteRule ^(([^/]+/)*[^/.]+)\.html$ http://waxxxed.com.au/$1 [R=301,L]
# www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.waxxxed.com.au
RewriteRule (.*) http://waxxxed.com.au/$1 [R=301,L]
# Redirect from / to non-/
RewriteEngine On
RewriteRule ^(.*)/$ $1 [R=301,NC,L]
# parse file as file.html
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(([^/]+/)*[^/.]+)$ $1.html [L]
# refer not found content to 404 page
ErrorDocument 404 /404page.html
答案 0 :(得分:2)
创建循环的原因是因为您检查主机名不是以ipad
开头,并且因为您要重定向到waxxxed.com.au
,它永远不会以ipad
开头。而是检查以/tablet/
开头的请求URI:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
对于#2,您需要查找其他平板电脑的用户代理。一般来说,你想找到“android”但不“mobile”:
RewriteCond %{HTTP_USER_AGENT} android [NC]
RewriteCond %{HTTP_USER_AGENT} !mobile [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
你的htaccess文件的其余部分看起来很好,只要它正在做你期望的事情,任何东西都会非常挑剔。