Another htaccess rewrite help

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

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

#RewriteRule ^public/css/(.)$
http://blahblah.cachefly.net/public/css/$1
#RewriteRule ^public/js/new_js/(.
)$
http://blahblah.cachefly.net/public/js/new_js/$1
#RewriteRule ^public/images/(.*)$
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 last;

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

#RewriteRule ^/public/css/(.)$
http://blahblah.cachefly.net/public/css/$1 last;
#RewriteRule ^/public/js/new_js/(.
)$
http://blahblah.cachefly.net/public/js/new_js/$1 last;
#RewriteRule ^/public/images/(.*)$
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:

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:

Tim,

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

RewriteCond %{HTTP_HOST} ^blahblah.com
RewriteRule ^(.*)$ 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;
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;
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
#RewriteRule ^public/js/new_js/(.
)$ http://blahblah.cachefly.net/public/js/new_js/$1
#RewriteRule ^public/images/(.*)$ 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;
}

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

thanks alot! and thanks to nginx irc chan :wink:

crossing my fingers on this.

Posted at Nginx Forum: