.htaccess 没有php扩展和漂亮的url nginx配置选项
我刚刚将代码从apache迁移到nginx服务器 我的apache.htaccess的替代nginx配置是什么 我使用的是删除.php扩展名和漂亮url重写的规则.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
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
处理。