Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Nginx URL Rewrite help.
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Nginx URL Rewrite help.

Hi, I'm new to nginx and just got a issue with URL rewrite. here is what I need to do. please help me if anyone know how to do it :)

www.example.com/filename.php?file=filenameone

to

www.example.com/filename/filenameone

Thanks !

Comments

  • htaccess

  • @VPSRAIDSolutions said:
    htaccess

    Did you even read the thread?

  • as far as I know htaccess will not work in nginx :3

  • htaccess is not working for nginx servers. correct me if I'm wrong.

  • edited October 2014

    Sorry didn't read it totally @Brad

    server {

    server_name www.vpsraid.com;

    root /var/www;

       location / {
                index index.php;
                try_files $uri $uri/ @www;
        }
    
        location @www {
                rewrite ^/filename/(.*) /filename.php?file=$1 last;
        }
    
        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass unix:/tmp/phpcgi.socket;
        }
    

    }

  • @HaroldM said:
    htaccess is not working for nginx servers. correct me if I'm wrong.

    check the above

  • you want rewrite or redirect to?

    rewrite ^filename/(.*)$ /filename.php?file=$1 last;

    /filename/aaa = /filename.php?file=aaa

  • rewrite ^/filename/(.*) /filename.php?file=$1 last;
    }

    sorry this part not working :/

    rokok said: you want rewrite or redirect to?

    rewrite :)

  • should working then, have you restart nginx yet?

  • @HaroldM said:

    did you copy the whole thing ?

    server {
    server_name www.vpsraid.com;
    root /var/www;

    too ?

  • edited October 2014

    <-->

  • rokok said: should working then, have you restart nginx yet?

    restarted, but nothing change. I already have these two lines.

    try_files $uri $uri/ @extensionless-php;

    and

    location @extensionless-php { rewrite ^(.*)$ $1.php last; }

    so I add this rewrite ^filename/(.*)$ /filename.php?file=$1 last; line under location @extensionless-php is that the problem ?

  • rokokrokok Member
    edited October 2014

    put below

    location / {

    ........

  • HaroldMHaroldM Member
    edited October 2014

    rokok said: Pastebin the whole config would help

    http://pastebin.com/M3qmVsRY

    here is what i have in my configuration file :) ( I replace example as my real domain name )

  • server {
        server_name www.example.com;
        access_log /home/webserver/example/logs/www/access.log;
        error_log /home/webserver/example/logs/www/error.log;
        root /home/webserver/example/public_html/www;
        index index.html index.htm index.php;
        rewrite ^/filename/(.*)$ /filename.php?file=$1 last;
     
        location / {
            try_files $uri $uri/ @extensionless-php;
        }
     
        location @extensionless-php {
            rewrite ^(.*)$ $1.php last;
        }
     
        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
     
        location ~ \.(aspx|jsp|cgi)$ {
            return 410;
        }
     
    }
  • @sleddog said:

    server {
    >     server_name www.example.com;
    >     access_log /home/webserver/example/logs/www/access.log;
    >     error_log /home/webserver/example/logs/www/error.log;
    >     root /home/webserver/example/public_html/www;
    >     index index.html index.htm index.php;
    >     rewrite ^/filename/(.*)$ /filename.php?file=$1 last;
    >  
    >     location / {
    >         try_files $uri $uri/ extensionless-php;
    >     }
    >  
    >     location extensionless-php {
    >         rewrite ^(.*)$ $1.php last;
    >     }
    >  
    >     location ~ \.php$ {
    >         include /etc/nginx/fastcgi_params;
    >         fastcgi_pass  127.0.0.1:9000;
    >         fastcgi_index index.php;
    >         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    >     }
    >  
    >     location ~ \.(aspx|jsp|cgi)$ {
    >         return 410;
    >     }
    >  
    > }

    wooh ... finally it's work. thank you very much :)

Sign In or Register to comment.