Sponsor:

Server and Web Integrator
Link:
Kloxo-MR logo
6.5.0 or 7.0.0
Click for "How to install"
Donation/Sponsorship:
Kloxo-MR is open-source.
Donate and or Sponsorship always welcome.
Click to:
Click Here
Please login or register. 2024-04-27, 16:45:31

Author Topic: How to rewrite urls in nginx ?  (Read 3670 times)

0 Members and 1 Guest are viewing this topic.

Offline djelica

  • Junior Member
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
How to rewrite urls in nginx ?
« on: 2014-11-11, 11:30:07 »
Alright, what i want to do is rewrite urls on one of my domains out of few.
For example i have 1stdomain.com and 2nddomain.com.
I want to rewrite urls only for 2nddomain.com and rewrites not to affect any other domains.
My kloxo version is: 6.5.0.f-2014091101

Until now i have tried modifying /home/nginx/conf/domains/2nddomain.com.conf but once i run fixweb and restart nginx, my changes are gone...

I want to do only one simple rewrite for now which for apache would look like this:
RewriteEngine On
RewriteCond    %{REQUEST_FILENAME}  !-f
RewriteCond    %{REQUEST_FILENAME}  !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ file.php?path=$1 [QSA,L]

End url should look like: www.2nddomain.com/some-path-goes-here/
It should be available for: http, https, www and non-www domain.

Please let me know where to put and what.

Offtopic:
I have noticed some strange behavior on default nginx installation which is that mydomain.com/any-path/any-depth/ leads to index file which isn't expected to happen, this can produce issues for some users who are duplicate-content aware. (this isn't good for SEO, not good at all).

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: How to rewrite urls in nginx ?
« Reply #1 on: 2014-11-11, 12:33:50 »
Don't change /home/nginx/conf/domains/2nddomain.com.conf directly but copy /home/nginx/tpl/domains.conf.tpl to custom.domains.conf.tpl and then modified this custom file. And then running 'sh /script/fixweb; sh /script/restart-web'.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline djelica

  • Junior Member
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How to rewrite urls in nginx ?
« Reply #2 on: 2014-11-11, 14:08:03 »
that file has over 1000 lines of code, what exactly should i edit?

Offline djelica

  • Junior Member
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: How to rewrite urls in nginx ?
« Reply #3 on: 2014-11-15, 05:02:14 »
still waiting for answer

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
Re: How to rewrite urls in nginx ?
« Reply #4 on: 2014-11-15, 16:13:58 »
1. Copy php-fpm_standard.conf and php-fpm_wildcards.conf to custom.php-fpm_standard.conf and custom.php-fpm_wildcards.conf in /opt/configs/nginx/conf/globals
2. Modified custom.php-fpm_standard.conf and custom.php-fpm_wildcards.conf in portion:
Code: [Select]
    location / {
        ## MR -- move to ~lxcenter.conf
        #limit_conn addr 25;

        try_files $uri $uri/ /index.php;
    }

to:
Code: [Select]
    location / {
        ## MR -- move to ~lxcenter.conf
        #limit_conn addr 25;

        #try_files $uri $uri/ /index.php;

        # YOUR NEW REWRITE HERE
    }

3. Run 'sh /script/fixweb; sh /script/restart-web -y'
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

 


MRatWork Affiliates:    BIGRAF(R) Inc.    House of LMAR    EFARgrafix
Click Here

Page created in 0.03 seconds with 22 queries.

web stats analysis