# Another htaccess rewrite help

**URL:** <https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260>\
**Category:** NGINX\
**Created:** [January 8, 2010, 12:22pm UTC](https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260 "2010-01-08T12:22:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darvil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@darvil](https://www.ruby-forum.com/u/darvil)\
**Post date:** [January 8, 2010, 12:22pm UTC](https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260/1 "2010-01-08T12:22:14Z")

</div>

Hey guys.

I posted this on WHT but I didn’t get the help I wanted. I’m helping  
someone move their site to nginx but they have some htaccess that I  
don’t know how to convert. I’ve done the easy rewrites but when it  
comes to the Cond statements I don’t know how to convert. I would  
really appreciate if you guys can help me. I’m doing this for a Russian  
site (ironically enough).

Original .htacess

AddDefaultCharset windows-1251  
RewriteEngine on  
RewriteCond %{HTTP\_HOST} ^blahblah.com  
RewriteRule ^(.\*)$ [http://www.blahblah.com/$1](http://www.blahblah.com/$1)

#flash card dat  
RewriteRule ^8\_marta.html$ public/8\_marta.php

#RewriteRule ^public/css/(._)$  
 [http://blahblah.cachefly.net/public/css/$1](http://blahblah.cachefly.net/public/css/$1)  
 #RewriteRule ^public/js/new\_js/(._)$  
[http://blahblah.cachefly.net/public/js/new\_js/$1](http://blahblah.cachefly.net/public/js/new_js/$1)  
#RewriteRule ^public/images/(.\*)$  
[http://blahblah.cachefly.net/public/images/$1](http://blahblah.cachefly.net/public/images/$1)

RewriteRule ^index.html$ public/index.html  
RewriteRule ^fcard\_data.xml$ system\_functions/get\_flash\_card\_slides\_xml  
RewriteRule ^fcard\_data\_(._).xml$  
system\_functions/get\_flash\_card\_slides\_xml/$1  
RewriteRule ^fcard\_user\_pic\_(._).xml$  
system\_functions/get\_flash\_card\_xml\_with\_user\_pic/$1  
RewriteRule ^session\_(._).xml$ flash\_cards/temp/session\_$1.xml  
RewriteRule ^saved\_(._).xml$ flash\_cards/saved/$1.xml  
RewriteRule ^(._)cloud\_data.xml$ system\_functions/get\_cloud\_xml  
RewriteRule ^site\_map.html$ site\_map  
RewriteRule ^sms\_test/zero.htm$ zero.htm  
 #flash templates  
RewriteRule ^(._)_shablon_(.\*).swf$ $1.swf

RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(._).html$ pages/$1.html  
RewriteRule ^(._).gz$ $1.gz

RewriteCond $1  
!^(index.php|public|music|temp|video|images|img|clipart|cat\_ico|pages|pictures|cast\_stone|artcl|banners|vc|mobile|mobile\_cards|phpMA2|myphpadmin3|fla  
sh\_cards|flash\_user|captcha|pcards|server.swf|client.swf|help.swf|user\_faces|bots.txt|favicon.ico|update.php|yandex\_57de7ec45e87f775.txt)

RewriteRule ^(.\*)$ index.php/$1

What I’ve done so far.

AddDefaultCharset windows-1251  
RewriteEngine on  
RewriteCond %{HTTP\_HOST} ^blahblah.com

rewrite ^/(.\*)$ [http://www.blahblah.com/$1](http://www.blahblah.com/$1) last;

#flash card dat  
rewrite ^/8\_marta.html$ public/8\_marta.php last;

#RewriteRule ^/public/css/(._)$  
 [http://blahblah.cachefly.net/public/css/$1](http://blahblah.cachefly.net/public/css/$1) last;  
 #RewriteRule ^/public/js/new\_js/(._)$  
[http://blahblah.cachefly.net/public/js/new\_js/$1](http://blahblah.cachefly.net/public/js/new_js/$1) last;  
#RewriteRule ^/public/images/(.\*)$  
[http://blahblah.cachefly.net/public/images/$1](http://blahblah.cachefly.net/public/images/$1) last;

rewrite ^/index.html$ public/index.html last;  
rewrite ^/fcard\_data.xml$ system\_functions/get\_flash\_card\_slides\_xml  
last;  
rewrite ^/fcard\_data\_(._).xml$  
system\_functions/get\_flash\_card\_slides\_xml/$1 last;  
rewrite ^/fcard\_user\_pic\_(._).xml$  
system\_functions/get\_flash\_card\_xml\_with\_user\_pic/$1 last;  
rewrite ^/session\_(._).xml$ flash\_cards/temp/session\_$1.xml last;  
rewrite ^/saved\_(._).xml$ flash\_cards/saved/$1.xml last;  
rewrite ^/(.\*)cloud\_data.xml$ system\_functions/get\_cloud\_xml last;  
rewrite ^/site\_map.html$ site\_map last;  
rewrite ^/sms\_test/zero.htm$ zero.htm last;

#flash templates  
rewrite ^/(._)shablon(._).swf$ $1.swf last;

RewriteCond %{REQUEST\_FILENAME} !-f  
rewrite ^/(._).html$ pages/$1.html last;  
rewrite ^/(._).gz$ $1.gz last;

RewriteCond $1  
!^(index.php|public|music|temp|video|images|img|clipart|cat\_ico|pages|pictures|cast\_stone|artcl|banners|vc|mobile|mobile\_cards|phpMA2|myphpadmin3|fla  
sh\_cards|flash\_user|captcha|pcards|server.swf|client.swf|help.swf|user\_faces|bots.txt|favicon.ico|update.php|yandex\_57de7ec45e87f775.txt)

rewrite ^/(.\*)$ index.php/$1 last;

Thanks

Tim

Posted at Nginx Forum:

> **[another htaccess rewrite help.](https://forum.nginx.org/read.php?2,38493,38493#msg-38493)**
>
> Hey guys. I posted this on WHT but I didn't get the help I wanted. I'm helping someone move their site to nginx but they have some htaccess that I don't know how to convert. I've done the easy rewrites but when it comes to the Cond statements I don't...

---

<div class="post-metadata">

**Author:** ![darvil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@darvil](https://www.ruby-forum.com/u/darvil)\
**Post date:** [January 12, 2010, 12:48am UTC](https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260/2 "2010-01-12T00:48:46Z")

</div>

Sorry for the bump but I would really appreciate it if someone can help  
me.

If I posted this in the wrong spot please let me know.

Tim

Posted at Nginx Forum:

> **[Re: another htaccess rewrite help.](https://forum.nginx.org/read.php?2,38493,39996#msg-39996)**
>
> Hey guys. I posted this on WHT but I didn't get the help I wanted. I'm helping someone move their site to nginx but they have some htaccess that I don't know how to convert. I've done the easy rewrites but when it comes to the Cond statements I don't...

---

<div class="post-metadata">

**Author:** ![darvil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@darvil](https://www.ruby-forum.com/u/darvil)\
**Post date:** [January 12, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260/3 "2010-01-12T23:31:27Z")

</div>

Tim,

All of the below is untested but it is how I would do it.

> RewriteCond %{HTTP\_HOST} ^blahblah.com  
> RewriteRule ^(.\*)$ [Boards · BlahBlah.com](http://www.blahblah.com/$1)  
> This first bit is a classic domain name canonicalization which in  
> nginx is accomplished by a small server block.

server {  
listen 80;  
server\_name [blahblah.com](http://blahblah.com);  
access\_log off;  
rewrite ^ http://www.blah.blah.com$request\_uri permanent;  
}

Next you’ll start the canonical server block…

server {  
listen 80;  
server\_name [blahblah.com](http://blahblah.com);  
root /path/to/root;

# Now let’s see what locations we will need.

> #flash card dat  
> RewriteRule ^8\_marta.html$ public/8\_marta.php

location = /8\_marta.html {  
rewrite ^ /public/8\_marta.php last;  
}

> #RewriteRule ^public/css/(._)$ [http://blahblah.cachefly.net/public/css/$1](http://blahblah.cachefly.net/public/css/$1)  
> #RewriteRule ^public/js/new\_js/(._)$ [http://blahblah.cachefly.net/public/js/new\_js/$1](http://blahblah.cachefly.net/public/js/new_js/$1)  
> #RewriteRule ^public/images/(.\*)$ [http://blahblah.cachefly.net/public/images/$1](http://blahblah.cachefly.net/public/images/$1)

# Though these were commented out, here’s one way to do all of them

with one location.

location ~ ^/public/(css|js/new\_js|images)/(.\*)$ {  
rewrite ^ [http://blahblah.cachefly.net/public/$1/$2](http://blahblah.cachefly.net/public/$1/$2);  
}

> RewriteRule ^index.html$ public/index.html

location = /index.html {  
alias /path/to/root/public;  
}

> RewriteRule ^fcard\_data.xml$ system\_functions/get\_flash\_card\_slides\_xml

location = /fcard\_data.xml {  
rewrite ^ /system\_functions/get\_flash\_card\_slides\_xml last;  
}

> RewriteRule ^fcard\_data\_(.\*).xml$ system\_functions/get\_flash\_card\_slides\_xml/$1

location ~ /fcard\_data\_(.\*).xml$ {  
rewrite ^ /system\_functions/get\_flash\_card\_slides\_xml/$1 last;  
}

> RewriteRule ^fcard\_user\_pic\_(.\*).xml$ system\_functions/get\_flash\_card\_xml\_with\_user\_pic/$1

location ~ /fcard\_user\_pic\_(.\*).xml$ {  
rewrite ^ /system\_functions/get\_flash\_xml\_with\_user\_pic/$1 last;  
}

> RewriteRule ^session\_(.\*).xml$ flash\_cards/temp/session\_$1.xml

location ~ /session\_(.\*).xml$ {  
rewrite ^ /flash\_cards/temp/session\_$1.xml last;  
}

> RewriteRule ^saved\_(.\*).xml$ flash\_cards/saved/$1.xml

location ~ /saved\_(.\*).xml$ {  
rewrite ^ /flash\_cards/saved/$1.xml last;  
}

> RewriteRule ^(.\*)cloud\_data.xml$ system\_functions/get\_cloud\_xml

location ~ cloud\_data.xml$ {  
rewrite /system\_functions/get\_cloud\_xml last;  
}

> RewriteRule ^site\_map.html$ site\_map

location = /site\_map.html {  
rewrite ^ /site\_map last;  
}

> RewriteRule ^sms\_test/zero.htm$ zero.htm

location = /sms\_test/zero.htm {  
alias /path/to/root;  
}

> #flash templates  
> RewriteRule ^(._)shablon(._).swf$ $1.swf

location ~ ^(._)shablon._.swf$ {  
rewrite ^ $1.swf;  
}

> RewriteRule ^(.\*).gz$ $1.gz

This one is pointless.. it just redirects to itself?

> RewriteCond $1 !^(index.php|public|music|temp|video|images|img|clipart|cat\_ico|pages|pictures|cast\_stone|artcl|banners|vc|mobile|mobile\_cards|phpMA2|myphpadmin3|fla sh\_cards|flash\_user|captcha|pcards|server.swf|client.swf|help.swf|user\_faces|bots.txt|favicon.ico|update.php|yandex\_57de7ec45e87f775.txt)
> 
> RewriteRule ^(.\*)$ index.php/$1
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteRule ^(.\*).html$ pages/$1.html

location / {  
try\_files $uri pages$uri /index.php$uri;  
}

# And now we’re done with the server block so one last thing:

}

– Merlin

---

<div class="post-metadata">

**Author:** ![darvil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@darvil](https://www.ruby-forum.com/u/darvil)\
**Post date:** [January 13, 2010, 12:07am UTC](https://www.ruby-forum.com/t/another-htaccess-rewrite-help/181260/4 "2010-01-13T00:07:09Z")

</div>

thanks alot! and thanks to #nginx irc chan 😉

crossing my fingers on this.

Posted at Nginx Forum:

> **[Re: another htaccess rewrite help.](https://forum.nginx.org/read.php?2,38493,40483#msg-40483)**
>
> Hey guys. I posted this on WHT but I didn't get the help I wanted. I'm helping someone move their site to nginx but they have some htaccess that I don't know how to convert. I've done the easy rewrites but when it comes to the Cond statements I don't...
