About setting up .htaccesses to redirect PCs and smartphones

Asked 2 months ago, Updated 2 months ago, 4 views

Because the URL of the PC site and the smartphone site are different, I tried to redirect them, and I set only the root domain of the server by writing the following in .htaccess.

When I accessed the top page of PC with my smartphone, it switched well, but the bottom page of PC is not reflected (it does not switch to the smartphone page).If you transition from the top page of the smartphone site to the bottom page (of course), the smartphone site will come out properly.If you enter the PC lower page directly, it will not switch to the smartphone lower page.Could you tell me what's wrong?

.htaccess describes:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond%{HTTP_USER_AGENT} (iPhone | Android.* Mobile | Windows.* Phone) [NC]
RewriteCond%{QUERY_STRING}!mode=pc
RewriteRule^$/smt/[R,L]
</IfModule>

The URL is as follows:


PC site http://www.〇 ..com/ or http://www.〇 ..com/index.html
Smartphone site http://www.〇〇.com/smt



PC Site http://www.〇 com.com/△△△.html
Smartphone site http://www.〇 com.com/smt/△△△.html

I apologize for the inconvenience, but I appreciate your cooperation.

.htaccess

2022-09-30 11:57

1 Answers

For .htaccess, the RewriteRule is subject to the RewriteRule where the first // 」 of the path // が is omitted. /
The ^$ of the current setting only covers the path // 」, so it is only the top page.
Consider a rule that excludes s/smt/ 」 from regular expressions, backward references, and redirect loops.

(Additional)
"If ""/some path"" → ""/smt/some path,"" the following settings are used:

"
RewriteRule^(.*)$/smt/$1[R,L]


2022-09-30 11:57

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.