我正在尝试通过.htaccess检测移动用户,并为他们添加一个?mobile = 1参数。我尝试了各种各样的东西,但这不会破坏WordPress。但是,我无法将其定位到具有子目录的URL。
RewriteCond %{QUERY_STRING} !(^|&)mobile=1(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?mobile=1 [L,QSA,R]
现在它适用于domain.com/?mobile。但是domain.com/2017/01/01/link/?mobile=1不起作用。
我尝试过以下(在其他各种事情中),当然它没有用。我知道我有一个更接近工作版本但不幸的是我没有把它保存为单独的文件。
RewriteCond %{QUERY_STRING} !(^|&)mobile=1(&|$) [NC]
RewriteRule ^/?$ /$0/mobile [L,NC,R]
有人想指出我正确的方向吗?
编辑:这是整个.htaccess。在默认规则之后,这是默认的WordPress .htaccess。
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos" [NC]
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 %{QUERY_STRING} !(^|&)mobile=1(&|$) [NC]
RewriteRule ^(.*)?$ %{REQUEST_URI}?mobile=1 [QSA,R]
答案 0 :(得分:0)
好的,我明白了。事实证明它只是在错误的顺序,我应该首先处理。这是最后的.htaccess:
<table class="tborder" id="threadslist" width="100%" cellspacing="1" cellpadding="5" border="0" align="center">
<tbody id="threadbits_forum_12">
<tr>
<td class="alt1" id="td_threadtitle_0001" title="">
<div>
<a href="showthread.php?t=0001" id="thread_title_0001">Random thread</a>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=100', '_self')">User</span>
</div>
</td>
</tr>
<tr>
<td class="alt1" id="td_threadtitle_0002" title="">
<div>
<a href="showthread.php?t=0002" id="thread_title_0002">Just a thread</a>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=100', '_self')">User</span>
</div>
</td>
</tr>
<tr>
<td class="alt1" id="td_threadtitle_0003" title="">
<div>
<a href="showthread.php?t=0003" id="thread_title_0003">Another thread</a>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=200', '_self')">Dude</span>
</div>
</td>
</tr>
<tr>
<td class="alt1" id="td_threadtitle_0004" title="">
<div>
<a href="showthread.php?t=0004" id="thread_title_0004">Useless thread</a>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=200', '_self')">Dude</span>
</div>
</td>
</tr>
<tr>
<td class="alt1" id="td_threadtitle_0005" title="">
<div>
<a href="showthread.php?t=0005" id="thread_title_0005">Intresting thread</a>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=300', '_self')">That guy</span>
</div>
</td>
</tr>
</tbody>
</table>