Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 没有php扩展和漂亮的url nginx配置选项_.htaccess_Nginx_Nginx Config - Fatal编程技术网

.htaccess 没有php扩展和漂亮的url nginx配置选项

.htaccess 没有php扩展和漂亮的url nginx配置选项,.htaccess,nginx,nginx-config,.htaccess,Nginx,Nginx Config,我刚刚将代码从apache迁移到nginx服务器 我的apache.htaccess的替代nginx配置是什么 我使用的是删除.php扩展名和漂亮url重写的规则 RewriteEngine On #remove .php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^([^\.]+)$ $1.php [NC,L] #for pretty url RewriteCond %{REQUEST_FILENAME} !-d RewriteC

我刚刚将代码从apache迁移到nginx服务器

我的apache.htaccess的替代nginx配置是什么

我使用的是删除.php扩展名和漂亮url重写的规则

RewriteEngine On

#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#for pretty url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?url=$1 [NC,L]
试试这个

map$uri$pretty\u url{
~/(.*)$    $1;
}
服务器{
...
地点/{
index index.php;#如果需要,将其替换为“index index.php index.html index.htm;”
尝试_文件$uri$uri/@extensionless php;
}
位置~\.php${
#这里是默认的PHP-FPM处理程序
...
}
location@extensionless php{
if(-f$document\u root$uri.php){
最后重写^$uri.php;
}
重写^/index.php?url=$pretty\uURL last;
}
}
试试这个

map$uri$pretty\u url{
~/(.*)$    $1;
}
服务器{
...
地点/{
index index.php;#如果需要,将其替换为“index index.php index.html index.htm;”
尝试_文件$uri$uri/@extensionless php;
}
位置~\.php${
#这里是默认的PHP-FPM处理程序
...
}
location@extensionless php{
if(-f$document\u root$uri.php){
最后重写^$uri.php;
}
重写^/index.php?url=$pretty\uURL last;
}
}

只需更改一行即可轻松修复。不需要额外的街区。您只需要在/etc/nginx/nginx.conf或/etc/nginx/sites available/your-site.com中更改这一行

将位置/指令try文件更改为:

location / {
       try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
}

希望这也适用于您:)

只需更改一行即可轻松修复。不需要额外的街区。您只需要在/etc/nginx/nginx.conf或/etc/nginx/sites available/your-site.com中更改这一行

将位置/指令try文件更改为:

location / {
       try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
}

希望这也适用于您:)

几乎可以回答您的问题,但上次的重写规则除外。我不是apache mod_rewrite的专家,你能告诉我像
example.com/some/pretty/URL
这样的URL应该如何重写吗?作为
index.php?url=/some/pretty/url
或作为
index.php?url=some/pretty/url
?@IvanShatsky嘿,它应该重写为index.php?url=some/pretty/url,没有slashWhat如果你收到像
example.com/some/pretty/url?a=b
?是否应将其处理为
index.php?url=some/pretty/url
(我当前的答案正是如此)或
index.php?url=some/pretty/url&a=b
?无法编辑我以前的注释,但我错了,查询参数应与该配置一起保留,请求
example.com/some/pretty/url?a=b
将作为
index.php?url=some/pretty/url&a=b
处理。几乎可以回答你的问题,除了你上次的重写规则。我不是apache mod_rewrite的专家,你能告诉我像
example.com/some/pretty/URL
这样的URL应该如何重写吗?作为
index.php?url=/some/pretty/url
或作为
index.php?url=some/pretty/url
?@IvanShatsky嘿,它应该重写为index.php?url=some/pretty/url,没有slashWhat如果你收到像
example.com/some/pretty/url?a=b
?是否应将其处理为
index.php?url=some/pretty/url
(我当前的答案正是如此)或
index.php?url=some/pretty/url&a=b
?无法编辑我以前的注释,但我错了,查询参数应与该配置一起保留,请求
example.com/some/pretty/url?a=b
将作为
index.php?url=some/pretty/url&a=b
处理。