寻找重写我的url,这样页面不会以/.php结尾。
例如,我想使'/about.php'看起来像'/ about'或'/ about /'
任何人都可以共享模块来做到这一点? 如果你有一个nginx.conf或者virtual.conf文件的例子来显示这种types的重写,我将不胜感激。
显然,我是一个小白,但试图通过实例学习。
您可以使用try_files指令来检查附加了.php的文件。 例如:
try_files $uri.php $uri;
这将首先查找/about.php ,然后处理/about如果它不存在。
location /about/ { proxy_pass http://backend/about.php; }
要么
# this will catch ALL files and rewrite ALL requests (like /blabla/file to /blabla/file.php) # it is not tested , but I guess you will understand this :) location / { rewrite ^/(.+)$ /$1.php break; proxy_pass http://backend; }
或者可能是最简单的方法
location / { proxy_path http://backend$uri.php #append .php to all files }
记住重写模块是慢的..尽量避免它