我的应用程序只有两个页面在移动设备或台式机上显示给用户。首先是登录页面,然后是应用程序页面本身。访问时www.myapp.com
,首先将用户索引到登录页面,并且如果他已登录,则将php重定向到应用程序页面。这是我的服务器架构:
root index.php (login page) mobile/mobile.php profile/profile.php
我希望避免用户使用www.myapp.com/mobile/mobile.php
,www.myapp.com/profile/profile.php
而www.myapp.com
和www.myapp.com/desktop
或www.myapp.com/mobile
这样,他还可以在布局之间切换。不幸的是,这在我的服务器上抛出了404错误:
nginx默认文件:
location ~ /mobile/mobile.php$ {
rewrite $host/mobile break;
}
location ~ /index.php$ {
rewrite $host break;
}
location ~ profile/profile.php$ {
rewrite $host/desktop break;
}
应该是这样还是其他完整方式?我想在我的服务器而不是用户设备中执行此操作。非常感谢您的帮助...
在我的开发服务器上测试了以下内容:
server {
listen 80;
root /usr/local/www/test;
index index.php;
location = /mobile { rewrite ^ /mobile/; }
location = /desktop { rewrite ^ /profile/; }
location / {
try_files $uri $uri/ =404;
}
location /mobile {
index mobile.php;
try_files $uri $uri/ =404;
}
location /profile {
index profile.php;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
它使用index
和try_files
查找脚本,然后在内部重定向到fastcgi
处理程序。我在upstream php { ... }
其他地方定义了。您可能会采用重写规则和internal
指令来强制URL栏上没有PHP脚本的方案。
移动重写只是为了保持与桌面重写的一致性,这样客户端就不会看到尾随/
。
这只是众多解决方案的一个例子。通常,存在一些辅助文件(css,js,图像)及其URL,这些辅助文件也需要容纳。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句