簡體   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