Pages rewrite

Francis Daly francis at daoine.org
Tue Jan 26 22:40:24 UTC 2016


On Fri, Jan 22, 2016 at 01:00:31PM -0500, blason wrote:

Hi there,

> I need a help on below topic and I wanted to achieve URL Rewrite like this
> 
> We want to redirect our domain pages from source to destination one
> 
> Source : Original Page
> www.xxxx.com/index.php?id=news
> 
> Destination :
> www.xxxxx.com/news.html

Option 1 - do it in php.

Write an index.php that will issue suitable 301 redirects for whatever
arguments it gets.

Option 2 - do it in nginx.conf.

In your "location = /index.php" block, use the appropriate logic.

If you know you will always get exactly one "id" parameter that will
always map to the obvious new url, something like

  return 301 /$arg_id.html;

(untested) would probably work. If you have different logic -- what
should happen with a request for /index.php?id=news&key=value, or for
/index.php?id1=news, or for /index.php?id=news&id=help, or for /index.php
-- then when you describe your intention, it may become obvious how to
implement it.

If it is straightforward, then http://nginx.org/r/map and examples
may help; if it is not, you may find it simpler to work in a different
language such as php.

(Note: in the above I have assumed that the source and destination
hostnames are the same. If they really are not, and the number of x's is
intentionally different, then you would need to include the full http://
url in the return directive.)

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list