繁体   English   中英

如果移动站点中不存在文件,如何将用户重定向到桌面站点?

[英]How to redirect users to the desktop site if the files doesn't exist in the mobile site?

我创建了www.example.comm.example.com m.example.com位于htdocs/m/文件夹中。 我在.htaccess使用以下代码:

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteRule ^(.*)$ m/$1 [L]

# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

现在,如果用户点击m.example.com/abc并且abc文件不存在,它将把用户重定向到错误页面,因为我在htdocs/m/文件夹中的.htaccess代码中有以下代码

ErrorDocument 404 http://m.example.com/error

但是,现在我希望将用户重定向到www.example.com/abc ,因为abc在桌面版本中可能是有效文件。 仅当桌面站点中也不存在文件时,用户才会被重定向到错误页面。

您可以将此规则作为第一规则放在m.example.com DocumentRoot中:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php !-f
RewriteRule ^(.+)$ http://www.example.com/$1 [L,R=302]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM