0

I have 2 separate websites, 1 is the main site for large devices such as laptop & pc.

https://example.com/

My 2nd site is for all mobile devices & tablets.

https://example.com/m

I found a post about this here,

So I edited from the following creating this

RewriteCond %{REQUEST_URI} !^/m/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

but it does not solve everything. It currently takes all requests from mobile device and directs them to

https://example.com/m

How can I make the following request from mobile device,

https://example.com/mywebpage1 => https://example.com/m/mywebpage1

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Have you tried this: https://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess ? – dev404 Jul 18 '20 at 06:00
  • Yes i seen this post before making a new one, none of the following recommends that involve redirect to subdirectory with following url work. The thread is backed almost 10 years ago, Both of these websites i have are wordpress websites, and i could not get plugins to work the way i need either. – Jeff Smith Jul 18 '20 at 06:24

1 Answers1

0
RewriteRule ^(.*)$ /m/ [L,R=302]

You are missing the $1 backreference in the substitution string. It should read:

RewriteRule ^(.*)$ /m/$1 [L,R=302]

The $1 backreference contains the contents of the capturing group (.*) in the RewriteRule pattern (ie. the URL-path). Without this it will redirect everything to /m/ as written.

MrWhite
  • 43,179
  • 8
  • 60
  • 84