1

使えるようになりたい

www.example.com/profiles/1234567890

それ以外の

www.example.com/profiles?id=1234567890

しかし、そうする方法を理解できませんでした。

ここで同等のApacheを見つけました:Turn text after slashes into variables with HTACCESS but I don't know how to work it to Nginx. である 1 つの変数だけが必要ですid

さらに、次のように書き換えることは可能ですか?

www.example.com/id/1234567890

に指差す

www.example.com/profiles/1234567890

URL変わらないの?

Nginxの設定

server {
    server_name www.domain.com;
    rewrite ^(.*) http://domain.com$1 permanent;
}

server {
    listen 80;
    server_name domain.com;
    root /var/www/domain.com/public;
    index index.php;

    access_log  /var/www/domain.com/access.log;
    error_log  /var/www/domain.com/error.log;

    rewrite ^/profiles?id=(.*)$ /profiles/$1 last;
    rewrite ^/id/(.*)$ /profiles/$1 last;
    
    # unless the request is for a valid file, send to bootstrap
    if (!-e $request_filename)
    {
        #rewrite ^(.+)$ /index.php?q=domain.com last;
        rewrite ^(.*)$ $1.php last;
    }
 
    # catch all
    error_page 404 /index.php;

    # Directives to send expires headers and turn off 404 error logging.
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
        access_log off;
    }

    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
               try_files $uri =404;
               root /usr/share/;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include /etc/nginx/fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
               root /usr/share/;
        }
    }
    location /phpMyAdmin {
        rewrite ^/* /phpmyadmin last;
    }
    
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }

    location / {
                # This is cool because no php is touched for static content. 
                # include the "?$args" part so non-default permalinks doesn't break when using query string                
                try_files $uri $uri/ @extensionless-php?$args;    
        }
    
    location @extensionless-php {
        rewrite ^(.*)$ $1.php last;
    }
    
    # use fastcgi for all php files
    location ~ \.php$
    {
        try_files $uri =404;

        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;

        # Some default config
        fastcgi_connect_timeout        20;
        fastcgi_send_timeout          180;
        fastcgi_read_timeout          180;
        fastcgi_buffer_size          128k;
        fastcgi_buffers            4 256k;
        fastcgi_busy_buffers_size    256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors    on;
        fastcgi_ignore_client_abort off;

    }
}
4

3 に答える 3

0

答えを探している人にとって、これはうまくいきました:

rewrite ^/profiles/([a-zA-Z0-9_-]+)$ /profile.php?id=$1;
rewrite ^/id/([a-zA-Z0-9_-]+)$ /profile.php?id=$1;
于 2013-07-07T08:18:40.627 に答える
0

I think you put the rules swapped, try something like

rewrite ^/(?:profiles|id)/(.*) /profiles?id=$1 last;
于 2013-05-15T03:20:02.020 に答える
0

構成ファイルの server ブロック内に、これを追加してみてください。

rewrite ^/profiles?id=(.*)$ /profiles/$1 last;
rewrite ^/id/(.*)$ /profiles/$1 last;

nginx を再起動します。それはうまくいくはずです。詳細については、http: //nginx.org/en/docs/http/ngx_http_rewrite_module.htmlを参照してください。

于 2013-04-27T19:35:33.963 に答える