# RewriteCond command

**URL:** <https://www.ruby-forum.com/t/rewritecond-command/202591>\
**Category:** NGINX\
**Created:** [February 2, 2011, 3:12am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591 "2011-02-02T03:12:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 2, 2011, 3:12am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/1 "2011-02-02T03:12:10Z")

</div>

hi i’ve seen many example that answered this forum and they use  
RewriteCond but if i put that command i get error nginx 0.8.3

RewriteCond %{request\_uri} !^index.php

if put my conf file it says

[emerg]: unknown directive “RewriteCond” in …

Posted at Nginx Forum:

> **[RewriteCond command](https://forum.nginx.org/read.php?2,171397,171397#msg-171397)**
>
> hi i've seen many example that answered this forum and they use RewriteCond but if i put that command i get error nginx 0.8.3 RewriteCond %{request\_uri} !^index\\.php if put my conf file it says \[emerg\]: unknown directive "RewriteCond" in...

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 3:32am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/2 "2011-02-02T03:32:14Z")

</div>

On 2 Fev 2011 02h11 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi i’ve seen many example that answered this forum and they use  
> RewriteCond but if i put that command i get error nginx 0.8.3
> 
> RewriteCond %{request\_uri} !^index.php  
> ^^^^^^^^^^^

This an Apache mod\_rewrite thing.

There’s no equivalent in Nginx. It uses a saner, more clear approach  
of a _single_ condition + rule in Apache terms.

Cf. [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule)

— appa

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 5:14am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/3 "2011-02-02T05:14:49Z")

</div>

thanks Antonio

if i could find to change & to ? i am going to solve my problem

incorrect  
[http://www.mysite.com/search/web&search=katy%20perry&type=web](http://www.mysite.com/search/web&search=katy%20perry&type=web)

correct  
[http://www.mysite.com/search/web?search=katy%20perry&type=web](http://www.mysite.com/search/web?search=katy%20perry&type=web)

what should i add into my conf  
server {  
listen 81;  
server\_name \*.mysite.ws;  
access\_log /var/log/mysite.access.log main;  
error\_log /var/log/mysite.error.log;  
root /home/mysite/www;  
index index.php index.html;

rewrite /(._)(style.css)$ /$2 last;  
rewrite /(._)(lightbox.css)$ /$2 last;  
rewrite /(._)(userdata/)(._)$ /$2$3 last;  
rewrite /(._)(maps/)(._)$ /$2$3 last;  
rewrite /(._)(test/)(._)$ /$2$3 last;  
rewrite ^/(._)(index.php)(/?)(._)$ /index.php?page=index/$4 last;  
rewrite /(._)(install/)(._)$ /$2$3 last;  
rewrite /(._)(addon/)(._)$ /$2$3 last;  
rewrite /(._)(cron/)(._)$ /$2$3 last;  
rewrite /(._)(js/)(._)(.js)$ /$2$3$4 last;  
rewrite /(._)(images/)(._)(.)(gif|jpe?g|png|ico)$ /$2$3$4$5 last;  
rewrite ^/(.\*)$ /index.php?page=$1 last;

location / {  
try\_files $uri $uri/ /index.php?q=$request\_uri;  
}

location ~ .php$ {  
root html;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME /home/mysite/www$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}

i couldnt convert this into my conf

RewriteCond %{request\_uri} !^index.php

Posted at Nginx Forum:

> **[Re: RewriteCond command](https://forum.nginx.org/read.php?2,171397,171425#msg-171425)**
>
> hi i've seen many example that answered this forum and they use RewriteCond but if i put that command i get error nginx 0.8.3 RewriteCond %{request\_uri} !^index\\.php if put my conf file it says \[emerg\]: unknown directive "RewriteCond" in...

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 10:46am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/4 "2011-02-02T10:46:10Z")

</div>

thanks Antonio its been fixed

Posted at Nginx Forum:

> **[Re: RewriteCond command](https://forum.nginx.org/read.php?2,171397,171484#msg-171484)**
>
> hi i've seen many example that answered this forum and they use RewriteCond but if i put that command i get error nginx 0.8.3 RewriteCond %{request\_uri} !^index\\.php if put my conf file it says \[emerg\]: unknown directive "RewriteCond" in...

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 6:02am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/5 "2011-02-02T06:02:20Z")

</div>

On 2 Fev 2011 04h12 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Try this:

location /search/web {  
rewrite ^ /search/web?$args?;  
}

> rewrite /(._)(style.css)$ /$2 last;  
> rewrite ^/(._)$ /index.php?page=$1 last;  
> There’s room for improvement above. You have rules that are repeated,  
> it just changes the second pattern. E.g.,

> rewrite /(._)(maps/)(._)$ /$2$3 last;  
> rewrite /(._)(test/)(._)$ /$2$3 last;  
> rewrite /(._)(install/)(._)$ /$2$3 last;  
> rewrite /(._)(addon/)(._)$ /$2$3 last;  
> rewrite /(._)(cron/)(._)$ /$2$3 last;

Can be placed in a single rule:

rewrite /(._)((maps|test|install|addon|cron)/)(._)$ /$2$3 last;

> }  
> }
> 
> i couldnt convert this into my conf
> 
> RewriteCond %{request\_uri} !^index.php

This is just the condition, what’s the rule?

if ($request\_uri != index.php) {  
(…)  
}

Note that an if is in fact an implicit location, so the only safe  
thing to do inside is to return a status code or a rewrite with the  
‘last’ flag. Cf. [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil)

— appa

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 5:22pm UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/6 "2011-02-02T17:22:01Z")

</div>

Hi Antonio,

thanks for your answer i added your code into conf but still didnt help  
when i type something in textbox system try to autocomplate i think  
livesearch but when you put space after a word its getting error, when i  
see access log i am receiving this

i try to search kylie i am typing kylie  
xx.xx.xx.xx - - [02/Feb/2011:16:58:37 +1100] “GET  
/index/livesearch&q=k&type=web HTTP/1.1” 200 491  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Wind$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:38 +1100] “GET  
/index/livesearch&q=ky&type=web HTTP/1.1” 200 31  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Wind$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:38 +1100] “GET  
/index/livesearch&q=kyl&type=web HTTP/1.1” 200 31  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Win$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:38 +1100] “GET  
/index/livesearch&q=kyli&type=web HTTP/1.1” 200 31  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Wi$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:39 +1100] “GET  
/index/livesearch&q=kylie&type=web HTTP/1.1” 200 31  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; W$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:39 +1100] “POST /search/redir  
HTTP/1.1” 302 5 “[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U;  
Windows NT 6.1; en-GB;$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:41 +1100] “GET  
/search/web?search=kylie&type=web&fl=0 HTTP/1.1” 200 13148  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Window$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:44 +1100] “GET  
/search/web?search=kylie&type=web&fl=0 HTTP/1.1” 200 13148  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Window$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:49 +1100] “GET / HTTP/1.1” 200 5078  
“[http://www.mysite.ws:81/search/web?search=kylie&type=web&fl=0](http://www.mysite.ws:81/search/web?search=kylie&type=web&fl=0)”  
"Mozilla/5.0 (Windows$

and then i hit enter it brings kylie results

i try to search kylie minogue i am typing kylie and space

xx.xx.xx.xx - - [02/Feb/2011:16:58:52 +1100] “GET  
/index/livesearch&q=k&type=web HTTP/1.1” 200 491  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Wind$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:52 +1100] “GET  
/index/livesearch&q=ky&type=web HTTP/1.1” 200 277  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Win$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:52 +1100] “GET  
/index/livesearch&q=kyl&type=web HTTP/1.1” 200 276  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; U; Wi$  
xx.xx.xx.xx - - [02/Feb/2011:16:58:53 +1100] “GET  
/index/livesearch&q=kylie%20&type=web HTTP/1.1” 200 752  
“[http://www.mysite.ws:81/](http://www.mysite.ws:81/)” "Mozilla/5.0 (Windows; $

and getting error not found

Error: Requested page was not found!  
Details: livesearch&q=kylie &type=web Action not found!  
Home

This is just the condition, what’s the rule?

if ($request\_uri != index.php) {  
(…)  
}

i think the rule is adding + request url if i dont put this command on  
htaccess apache automaticly adding %20 between words on the result page  
if i put this into htaccess its automaticly adding + between result  
words on result page

for instance

[http://www.mysite.com/search/web?search=katy+perry&type=web](http://www.mysite.com/search/web?search=katy+perry&type=web)  
with RewriteCond

[http://www.mysite.com/search/web?search=katy%20perry&type=web](http://www.mysite.com/search/web?search=katy%20perry&type=web)  
without RewriteCond

they both working btw

Posted at Nginx Forum:

> **[Re: RewriteCond command](https://forum.nginx.org/read.php?2,171397,171450#msg-171450)**
>
> hi i've seen many example that answered this forum and they use RewriteCond but if i put that command i get error nginx 0.8.3 RewriteCond %{request\_uri} !^index\\.php if put my conf file it says \[emerg\]: unknown directive "RewriteCond" in...

---

<div class="post-metadata">

**Author:** ![lifeisjustabout](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@lifeisjustabout](https://www.ruby-forum.com/u/lifeisjustabout)\
**Post date:** [February 2, 2011, 11:02am UTC](https://www.ruby-forum.com/t/rewritecond-command/202591/7 "2011-02-02T11:02:30Z")

</div>

On Tue, Feb 01, 2011 at 09:11:03PM -0500, lifeisjustabout wrote:

> hi i’ve seen many example that answered this forum and they use  
> RewriteCond but if i put that command i get error nginx 0.8.3
> 
> RewriteCond %{request\_uri} !^index.php

This should be translated from Yoda backward style to nginx forward  
style:

location = /index.php {  
…  
}

location / {  
…  
}

–  
Igor S.

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