【问题标题】:.htaccess redirect all site pages to one page m.htaccess 将所有站点页面重定向到一页 m
【发布时间】:2019-03-31 06:14:54
【问题描述】:

我有 wordpress 网站和一页 html m。移动访问者的网站。 我想将其移动访问者的所有 wordpress 页面重定向到 m。 (一页html)。 我使用此代码,但它仅适用于主页。

RewriteEngine on
RewriteBase /
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:www.website.com]

# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
#  had to check, but I believe most mobile devices should send at
#  least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]

# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 

# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]

# Now redirect to the mobile site
RewriteRule ^ http://m.website.com [R,L]

【问题讨论】:

标签: php wordpress .htaccess


【解决方案1】:

要将所有页面重定向到相应的移动页面,您应该能够将最后一行替换为:

RewriteRule ^(.*)$ http://m.website.com/$1 [R,L]

编辑:要将所有页面重定向到一个移动页面,请使用

RewriteRule ^(.*)$ http://m.website.com/ [R,L]

除此之外,最好不要在两个地方提供相同的内容(问题:桌面共享移动链接、搜索引擎...),而是使用 css 媒体查询或服务器端技术来改变风格,如果可能的话。

【讨论】:

  • 感谢重播,但仅主页重定向到 m 不起作用。其他页面不重定向。有其他想法吗?
  • 我刚刚测试了这个确切的配置。你确定替换最后一行,即把^改成^(.*)$
  • 另外:你在哪里添加了规则?也许他们正在干扰 Wordpress 重写规则?也许还可以看到 wordpress.stackexchange.com/questions/189767/… 以获取 Wordpress 原生解决方案(对于没有 is_front_page() 的您)
猜你喜欢
  • 1970-01-01
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-29
  • 2021-03-05
相关资源
最近更新 更多