Glen_L
February 19, 2010, 9:11am
1
Hi Nginx,
I’m migrating my website into onother application. I need to rewrite
some of
these
http://www.mydomain.com/category/subcategory
into
Small business web hosting offering additional business services such as: domain name registrations, email accounts, web services, and various small business solutions.
http://www.mydomain.com/application/category/subcategory
application/category/subcategory
I need to insert /application before my category name
Thank’s before
Glen_L
February 19, 2010, 10:10am
2
On Fri, Feb 19, 2010 at 03:11:09PM +0700, Glen L. wrote:
http://www.mydomain.com/application/category/subcategory
I need to insert /application before my category name
If you use proxying, then:
location / {
proxy_pass http://backend/application/;
}
–
Igor S.
http://sysoev.ru/en/
Glen_L
February 19, 2010, 11:03am
3
No i’m not proxying…
Because all I need is to rewrite arround 50 that category
Glen_L
February 19, 2010, 11:06am
4
On Fri, Feb 19, 2010 at 05:02:44PM +0700, Glen L. wrote:
No i’m not proxying…
What do you use ?
Because all I need is to rewrite arround 50 that category
Could you show some examples ?
I’m migrating my website into onother application. I need to rewrite some
I need to insert /application before my category name
Igor Sysoev
nginx Info Page
–
Igor S.
Igor Sysoev
Glen_L
February 19, 2010, 11:46am
5
Glen_L
February 19, 2010, 11:51am
6
Is that posibble to use somethink like
location ~ ^/breaking-news|national|...) {
rewrite ^ /category$request_uri
}
?
Glen_L
February 19, 2010, 11:47am
7
On Fri, Feb 19, 2010 at 05:11:14PM +0700, Glen L. wrote:
I’m using php-fpm for these
Something like this:
location ~ ^/breaking-news|national|...) {
fastcgi_pass ...
fastcgi_parm SCRIPT_FILENAME /path/to/scripts/category$uri;
...
}
What do you use ?
proxy_pass http://backend/application/;
nginx Info Page
nginx mailing list
[email protected]
nginx Info Page
nginx mailing list
[email protected]
nginx Info Page
–
Igor S.
http://sysoev.ru/en/
Glen_L
February 19, 2010, 11:51am
8
On Fri, Feb 19, 2010 at 05:20:20PM +0700, Glen L. wrote:
Is that posibble to use somethink like
location ~ ^/breaking-news|national|...) {
rewrite ^ /category$request_uri
}
?
Possible, but why to use rewrite, if you may pass request directly where
you want ? In my opinion rewrites cause spaghetti configuration.
Old : http://www.mydomain.com/breaking-news
Something like this:
To: [email protected]
Could you show some examples ?
http://www.mydomain.com/application/category/subcategory
–
nginx mailing list
nginx Info Page
nginx mailing list
[email protected]
nginx Info Page
nginx mailing list
[email protected]
nginx Info Page
–
Igor S.
http://sysoev.ru/en/
Glen_L
February 19, 2010, 12:04pm
9
I prefer to rewrite it, because what we concerned is google indexing…
sometimes google will remove the old address, and getting the new one
So that when people accessing our site, they will bookmark the new
address
Glen_L
February 21, 2010, 7:37am
11
On Sat, Feb 20, 2010 at 8:17 PM, Glen L. [email protected]
wrote:
Bump…
you should start learning writing rewrite rules…
rewrite ^/news/(.+)/title
http://app.mydomain.com/redirect/application/$1 permanent;
Glen_L
February 19, 2010, 12:43pm
12
OK thank’s for ur suggestion… It’s working like a charm… 1 more
question
I have a url http://www.mydomain.com/news/$id/title
How can I redirect it to
http://app.mydomain.com/redirect/application/$id ?
Glen_L
February 21, 2010, 7:58am
13
On Sat, Feb 20, 2010 at 8:45 PM, Glen L. [email protected]
wrote:
Is that posibble to detect if (.+) is numbers only?
yes.
the method should be mentioned in any guide about regular expressions.
Which includes this [1] and this [2].
[1] PCRE Regular Expression Pattern Syntax Refference (PHP preg*)
[2] Regular Expressions Reference
–
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Glen_L
February 21, 2010, 7:48am
14
Glen_L
February 21, 2010, 8:08am
15
Thank’s for your prompt reply…
However i tried this
rewrite “/news/([0-9] {2})([0-9] {2})([0-9] {2})/$”
http://app.mydomain.com/redirect/application/$1$2$3 ;
but it doesn’t work. What I’ve missed?
Glen_L
February 21, 2010, 8:39am
16
the spaces: “] {” -> “]{”.
may i ask why you catch three times two numbers instead of one time six?
Glen_L
February 21, 2010, 8:44am
17
Glen L. a écrit :
Thank’s for your prompt reply…
However i tried this
rewrite “/news/([0-9] {2})([0-9] {2})([0-9] {2})/$”
http://app.mydomain.com/redirect/application/$1$2$3 ;
but it doesn’t work. What I’ve missed?
The regexp pattern isn’t correct. You shouldn’t have spaces before
the “{2}” unless you really want to match two consecutive spaces.
Even without those spaces, this pattern would match urls like
“/news/123456/” (without “/title” and with a trailing slash), while
you said you need to match “/news/$id/title” instead. Also, if you
want to fade out the old url in the long run, you could use a
permanent redirect.
You probably want something like that:
rewrite ^/news/([0-9]{6})/title$
http://app.mydomain.com/redirect/application/$1 permanent;
Glen_L
February 21, 2010, 8:43am
18
The spaces fixed the problem
By the way, if i have only 1, 2, 3, 4, 5 digits of numbers, it’s not
redirected
Glen_L
February 21, 2010, 8:48am
19
honestly, i think you should really go through some regex tutorials
Glen_L
February 21, 2010, 8:58am
20
It means that if I have 6 digits of numbers, it will redirect to the url
i’ve described
But if I have 5 digits of numbers, it’s not redirecting to the URL.