# Pages rewrite

**URL:** <https://www.ruby-forum.com/t/pages-rewrite/243892>\
**Category:** NGINX\
**Created:** [January 22, 2016, 9:51pm UTC](https://www.ruby-forum.com/t/pages-rewrite/243892 "2016-01-22T21:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [January 22, 2016, 9:51pm UTC](https://www.ruby-forum.com/t/pages-rewrite/243892/1 "2016-01-22T21:51:29Z")

</div>

Hi Guys,

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](http://www.xxxx.com/index.php?id=news)

Destination :  
[www.xxxxx.com/news.html](http://www.xxxxx.com/news.html)

Posted at Nginx Forum:

> **[Pages rewrite](https://forum.nginx.org/read.php?2,264068,264068#msg-264068)**
>
> Hi Guys, 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.xx

---

<div class="post-metadata">

**Author:** ![blason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e68b1a/32.png) [@blason](https://www.ruby-forum.com/u/blason)\
**Post date:** [January 26, 2016, 8:03am UTC](https://www.ruby-forum.com/t/pages-rewrite/243892/2 "2016-01-26T08:03:41Z")

</div>

Hi Team,

Any update I am still failing to achieve the same? How do I rewrite the  
URLs

Posted at Nginx Forum:

> **[Re: Pages rewrite](https://forum.nginx.org/read.php?2,264068,264120#msg-264120)**
>
> Hi Guys, 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.xx

---

<div class="post-metadata">

**Author:** ![blason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e68b1a/32.png) [@blason](https://www.ruby-forum.com/u/blason)\
**Post date:** [January 26, 2016, 11:40pm UTC](https://www.ruby-forum.com/t/pages-rewrite/243892/3 "2016-01-26T23:40:44Z")

</div>

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  
> [XXXX](http://www.xxxx.com/index.php?id=news)
> 
> Destination :  
> [www.xxxxx.com/news.html](http://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 [Module ngx\_http\_map\_module](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 D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
