php - Document root for mobile version (.htaccess?) -


i have webshop, , since google decided promote mobile versions of webpages, developing m.example.com.

here trick. not want, m. domain. want is, when user coming, check user agent, , if coming mobile, show mobile version, if come desktop, show desktop version.

but, want use same urls users. so, http://example.com/contact/ url both desktop users, , both mobile users.

the mobile version of page under subdirectory ./mobile/.

is possible somehow force apache, change document root, if coming mobile, keep original urls?

for example:

http://example.com/contact/ should run /var/apache/example.com/mobile/contact.php, desktop version, should run /var/apache/example.com/contact.php? mentioned, urls same.

if question not clear, please leave comment.

something this? (collated this answer , doing rewriterule)

rewriteengine on  # check if noredirect query string rewritecond %{query_string} (^|&)noredirect=true(&|$) # set cookie, , skip next rule rewriterule ^ - [co=mredir:0:%{http_host},s]  # check if looks mobile device # (you add [or] second 1 , add in #  had check, believe mobile devices should send @ #  least 1 of these headers) rewritecond %{http:x-wap-profile} !^$ [or] rewritecond %{http:profile}       !^$ # check if we're not on mobile site rewritecond %{http_host}          !^m\. # check make sure haven't set cookie before rewritecond %{http:cookie}        !\smredir=0(;|$) # redirect mobile site rewriterule ^(.*)$  mobile/$1 [r,l] 

credit must go original answer - mobile redirect using htaccess


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -