Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48981

.htaccess redirection from desktop to mobile (PWA) and vice versa

$
0
0

I have fully functional desktop site, made with PHP which I have created long back ago. Now I have planned to move to ionic for app and PWA. Therefore I am using Ionic5 with angular11 to create the mobile site(PWA), SPA.
desktop site =>https://www.example.com
mobile site => https://m.example.com

But right now I cant replace the desktop site with Ionic. So now I want to redirect users to desktop or mobile site as per their devices via .htaccess

For desktop => Mobile (.htaccess file is placed at root folder of the domain)

RewriteEngine on

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [QSA,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

RewriteCond %{HTTPS} off 
RewriteCond %{SERVER_PORT} 8181 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

RewriteCond %{QUERY_STRING} !^desktop
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]
RewriteRule ^$ https://m.example.com [L,R=302]

This is working fine to redirect users from desktop site to mobile site.

For mobile=> desktop (.htaccess file is in subdomain folder (m.example.com))
Currently I’m using the following for Ionic PWA

<IfModule mod_rewrite.c>
  RewriteEngine On
  
  # Redirection to HTTPS:
  RewriteCond %{HTTPS} !on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
  # Redirection of requests to index.html
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -s [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^.*$ - [NC,L]
  # Redirect all non-file routes to index.html
  RewriteRule ^(?!.*\.).*$ index.html [NC,L]
</IfModule>

But to redirect users to desktop site, tried to put the following

  RewriteEngine On
  RewriteCond %{HTTP_USER_AGENT} !(iphone|ipad|android|blackberry|windows\ phone) [NC]
  RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
  RewriteRule ^$ https://www.example.com [L,R=302]

but it is not working.

Can you help me with this? :pray::pray:

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>