.htaccess移动检测和重写

时间:2016-10-30 14:08:33

标签: .htaccess mod-rewrite caching mobile detection


我有个问题。

我想在我的.htaccess中添加移动侦测功能。但我不明白。

此代码位于我的.htaccess

RewriteEngine on
RewriteBase /


###### Cache ######
# Check if the requested file exists in the cache, otherwise default to index.php
RewriteCond %{DOCUMENT_ROOT}/cache/desktop/%{REQUEST_URI}.html !-f
RewriteRule .* - [E=SFC_FILE:/index.php]

# Check if a static file actually exists.
RewriteCond %{DOCUMENT_ROOT}/cache/desktop/%{REQUEST_URI}.html -f

# Rewrite the request to the static file.
RewriteRule .* %{DOCUMENT_ROOT}/cache/desktop/%{REQUEST_URI}.html [L]

###### /Cache ######


RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Change to RewriteBase /cms/ if CMSMS is installed in this subdirectory


# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# COMMENT Monolingual rule and UNCOMMENT MLE rule
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

###### Static Cache ######部分,我想添加检测。您可以看到路径中有/desktop/个部分。 移动检测必须重定向到/ mobile /.

我发现了很多移动设备检测,例如:Custom .htaccess mobile redirection

但我不明白如何将它与我的代码结合起来。

任何人都可以帮助我吗?

非常感谢!

0 个答案:

没有答案