gpt4 book ai didi

url-rewriting - 使用 NginX 和 Laravel : URL Rewrites

转载 作者:行者123 更新时间:2023-12-04 12:26:45 27 4
gpt4 key购买 nike

我正在尝试在运行 CentOS 6.4 和 NginX 1.8 的 VPS 上设置 Laravel 框架。我可以让其他一切都完美地工作,除了我无法让更清晰的 URL 工作,比如使用“website.com/home”而不是“website.com/index.php/home”。谁能帮忙?这是目前我的虚拟主机配置文件的内容。

server {

listen 80;
server_name swati.havok.semicolony.com;
access_log /usr/share/nginx/semicolony.com/_subdomains/swati/storage/logs/access.log;
error_log /usr/share/nginx/semicolony.com/_subdomains/swati/storage/logs/errors.log;

root /usr/share/nginx/semicolony.com/_subdomains/swati/public;
index index.php;

#browse folders if no index file
autoindex on;

# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}

# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
#expires max;
}

# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}

# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root /usr/share/nginx/semicolony.com/_subdomains/swati/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

编辑:我使用的 Laravel 4 可能很重要。

最佳答案

我对 Nginx 不是很熟悉,但我确实认为您的重写正则表达式不正确。

尝试改变

重写 ^/(.*)$/index.php?/$1 最后;

收件人:

最后重写^/(.*)$/index.php/$1;

或者:

最后重写^.*$/index.php;

关于url-rewriting - 使用 NginX 和 Laravel : URL Rewrites,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15864771/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com