我想知道如何使我的网站URL与我的网站目录中的文件路径不同。
例如,假设我希望我的网站语言在URL(mywebsite/en/index.php(中,但我不想手动在我的网站目录中创建每个php文件,其中只包含主文件中的一个include,我该怎么做呢?如果需要,我会使用Nginx
您可以使用nginx重写regex规则。Nginx重写规则
假设您希望下面的url使用语言代码访问index.php。
Url: https://yourwebsite.com/en/index.php
FilePath: /path/to/www/index.php
rewrite ^/(.*)/index.php$ /index.php?lang=$1 last;
# another example
# $1 is the matching characters in regex `(.*)`
rewrite ^/sales/(.*)/categories.php$ /some/path/cat.php?categories=$1 last;
别忘了。所有URL都是虚构的,但所有文件都是真实的。URL不需要与真实文件匹配。URL:https://yourwebsite.com/index.php
可能命中/some.file.asp
有关更多详细信息,请参阅nginx官方文档。
希望,它有帮助。