英文:
Why isn't my Nginx try_files directive working to remove an extension
问题
My site is a basic PHP site with a WordPress blog installed in a subdirectory. I need to use pretty URLs, so I need to remove the .php
extension from the files in root, and then get WordPress to behave like WordPress in the /blog
subdirectory.
这是一个基本的PHP网站,其中安装了一个WordPress博客在一个子目录中。我需要使用漂亮的URL,所以我需要从根目录中删除文件的.php
扩展名,然后让WordPress在/blog
子目录中正常工作。
I've only been able to get one to work at a time and can't figure out what I'm doing wrong.
我一次只能让一个部分工作,无法弄清楚我做错了什么。
This config works for WordPress, but downloads the .php files in root. :/
这个配置适用于WordPress,但会下载根目录中的.php文件。:/
英文:
My site is a basic PHP site with a WordPress blog installed in a subdirectory. I need to use pretty URLs, so I need to remove the .php
extension from the files in root, and then get WordPress to behave like WordPress in the /blog
subdirectory.
I've only been able to get one to work at a time and can't figure out what I'm doing wrong.
This config works for WordPress, but downloads the .php files in root. :/
location / {
try_files $uri $uri/ /$uri.php /blog/index.php?$query_string;
}
UPDATE
I've added a separate location
so now the extension removal is working in root, but the blog links just go back to the site's home page
location / {
try_files $uri $uri/ $uri.php;
}
location /blog {
try_files $uri $uri/ /index.php?$query_string;
}
// also tried this, with the same results
location /blog {
try_files $uri $uri/ /index.php;
}
答案1
得分: 0
I needed to add /blog/
as a path inside the /blog
/location
:
将`/blog/`添加为`/blog` `/location`内的路径:
location / {
try_files $uri $uri/ $uri.php;
}
location /blog {
try_files $uri $uri/ /blog/index.php;
}
英文:
Figured it out. I needed to add /blog/
as a path inside the /blog
/location
location / {
try_files $uri $uri/ $uri.php;
}
location /blog {
try_files $uri $uri/ /blog/index.php;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论