another htaccess rewrite help.

merlin corey merlincorey at dc949.org
Wed Jan 13 01:30:41 MSK 2010


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



More information about the nginx mailing list