# Rewrite with apostrophe causes 404

**URL:** <https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071>\
**Category:** NGINX\
**Created:** [May 23, 2010, 10:48pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071 "2010-05-23T22:48:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [May 23, 2010, 10:48pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071/1 "2010-05-23T22:48:40Z")

</div>

Hello,

videos/1432/so-it/'s-ok-karyn-garcia

above causes 404

if i manually edit the url to videos/1432/so-it’s-ok-karyn-garcia it  
works

Here is the rewrite rule

rewrite ^/videos/([^/]_)/([^/]_)$ /play.php?vid=$1 last;

Can you tell me how can i fix this ?

Thanks.

Posted at Nginx Forum:

> **[Rewrite with apostrophe causes 404](https://forum.nginx.org/read.php?2,89455,89455#msg-89455)**
>
> Hello, videos/1432/so-it/'s-ok-karyn-garcia above causes 404 if i manually edit the url to videos/1432/so-it's-ok-karyn-garcia it works Here is the rewrite rule rewrite ^/videos/(\[^/\]\*)/(\[^/\]\*)$ /play.php?vid=$1 last;

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [May 23, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071/2 "2010-05-23T23:39:35Z")

</div>

on opera and firefox the urls are automatically corrected and workin  
with the rewrite rules like follows

videos/1432/so-it%5C%27s-ok-karyn-garcia

but on internet explorer its not being corrected.

Posted at Nginx Forum:

> **[Re: Rewrite with apostrophe causes 404](https://forum.nginx.org/read.php?2,89455,89476#msg-89476)**
>
> Hello, videos/1432/so-it/'s-ok-karyn-garcia above causes 404 if i manually edit the url to videos/1432/so-it's-ok-karyn-garcia it works Here is the rewrite rule rewrite ^/videos/(\[^/\]\*)/(\[^/\]\*)$ /play.php?vid=$1 last;

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [August 22, 2010, 2:26pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071/3 "2010-08-22T14:26:01Z")

</div>

I solved this myself, forgot to put the solution here, the following  
removes /’ and replaces it with nothing so urls work in all browsers.

if ($uri ~ “^(._)/'(._)$”){  
set $rule\_0 1$rule\_0;  
set $bref\_1 $1;  
set $bref\_2 $2;  
}  
if ($rule\_0 = “1”){  
rewrite /. /$bref\_1$bref\_2 permanent;  
break;  
}

Maybe this will help someone too.

Posted at Nginx Forum:

> **[Re: Rewrite with apostrophe causes 404](https://forum.nginx.org/read.php?2,89455,122369#msg-122369)**
>
> Hello, videos/1432/so-it/'s-ok-karyn-garcia above causes 404 if i manually edit the url to videos/1432/so-it's-ok-karyn-garcia it works Here is the rewrite rule rewrite ^/videos/(\[^/\]\*)/(\[^/\]\*)$ /play.php?vid=$1 last;

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [August 22, 2010, 8:06pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071/4 "2010-08-22T20:06:42Z")

</div>

On Sun, May 23, 2010 at 04:47:49PM -0400, st1905 wrote:

> rewrite ^/videos/([^/]_)/([^/]_)$ /play.php?vid=$1 last;
> 
> Can you tell me how can i fix this ?

location = /videos/1432/so-it/'s-ok-karyn-garcia {  
fastcgi\_pass …  
include fastcgi\_params;  
fastcgi\_param SCRIPT\_FILENAME /path/to/play.php;  
fastcgi\_param QUERY\_STRING vid=1432/so-it/'s-ok-karyn-garcia;  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![st1905](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@st1905](https://www.ruby-forum.com/u/st1905)\
**Post date:** [August 24, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/rewrite-with-apostrophe-causes-404/189071/5 "2010-08-24T16:46:17Z")

</div>

Thanks a lot Igor. It works just like the way it should be but there are  
thousands of videos and i dont know how many of them have this issue.

Posted at Nginx Forum:

> **[Re: Rewrite with apostrophe causes 404](https://forum.nginx.org/read.php?2,89455,123143#msg-123143)**
>
> Hello, videos/1432/so-it/'s-ok-karyn-garcia above causes 404 if i manually edit the url to videos/1432/so-it's-ok-karyn-garcia it works Here is the rewrite rule rewrite ^/videos/(\[^/\]\*)/(\[^/\]\*)$ /play.php?vid=$1 last;
