i've been trying to convert this .htaccess for a week now

Steve steeeeeveee at gmx.net
Wed Dec 30 14:27:41 MSK 2009


-------- Original-Nachricht --------
> Datum: Tue, 29 Dec 2009 20:35:15 -0600
> Von: "AMP Admin" <admin at ampprod.com>
> An: nginx at nginx.org
> Betreff: RE: i\'ve been trying to convert this .htaccess for a week now

> Wow!  This is awesome!  I'll start working with this and see what I can
> come
> up with.
> 
It would help if you could post the whole configuration you use for that software. I mean the nginx part. Then others could easier tell if a "last", "break" or "permanent" should be used in the rewrite conditions.

What web application is that what you use over there? I mean: What software needs those rewrite rules? Is it something open that can be downloaded from the web?


> Btw, I'm running Nginx 0.7.64
> 
Thanks.


> -----Original Message-----
> From: Steve [mailto:steeeeeveee at gmx.net] 
> Sent: Tuesday, December 29, 2009 7:53 PM
> To: nginx at nginx.org
> Subject: Re: i've been trying to convert this .htaccess for a week now
> 
> 
> -------- Original-Nachricht --------
> > Datum: Mon, 28 Dec 2009 20:24:14 -0600
> > Von: "AMP Admin" <admin at ampprod.com>
> > An: nginx at nginx.org
> > Betreff: i\'ve been trying to convert this .htaccess for a week now
> 
> > I hate to ask but this one is just too big and complicated for me to
> > convert.  Any help would be good.  Thanks!
> > 
> >  
> > 
> [removed long list of Apache Rewrite rules]
> >
> >
> Since I don't know where you need those rewrites and what version of nginx
> you are using and how you have setup the other stuff in nginx I am not
> able
> to optimize the rewrite rules (some stuff can be done without rewriting
> when
> using newer version of nginx). Anyway.... here a suggestion (you might
> need
> to change "permanent" to "last" or in some cases to "break" but all this
> depends where you add those rewrite rules in your nginx.conf):
> --------------------------
> rewrite ^/articles/?$  /articles.php  permanent;
> rewrite ^/articles/([^/.]+)/?$
> /articles.php?action=viewarticle&articleUri=$1?  permanent;
> rewrite ^/articles/category/([^/.]+)/?$
> /articles.php?action=viewcategory&articleCatUri=$1?  permanent;
> 
> rewrite ^/news/?$  /news.php  permanent;
> rewrite ^/news/([^/.]+)/?$  /news.php?newsUri=$1?  permanent;
> 
> rewrite ^/blogs/?$  /blogs.php  permanent;
> rewrite ^/blogs/all/(\d+)/(\d+)/?$  /blogs.php?page=$2&per_page=$1?
> permanent;
> rewrite ^/blogs/top/?$  /blogs.php?action=top_blogs?  permanent;
> rewrite ^/blogs/top/(\d+)/(\d+)/?$
> /blogs.php?action=top_blogs&page=$2&per_page=$1?  permanent;
> rewrite ^/blogs/top_posts/?$  /blogs.php?action=top_posts?  permanent;
> rewrite ^/blogs/tag/([^/.]+)/?$ 
> /blogs.php?action=search_by_tag&tagKey=$1?
> permanent;
> rewrite ^/blogs/tag/?$  /blogs.php?action=search_by_tag&tagKey=? 
> permanent;
> rewrite ^/blogs/posts/([^/.]+)/tag/([^/.]+)/?$
> /blogs.php?action=search_by_tag&tagKey=$2&ownerName=$1?  permanent;
> rewrite ^/blogs/posts/([^/.]+)/category/([^/.]+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&categoryUri=$2? 
> permanent;
> rewrite ^/blogs/entry/([^/.]+)/?$
> /blogs.php?action=show_member_post&postUri=$1?  permanent;
> rewrite ^/blogs/entry/?$  /blogs.php?action=show_member_post&postUri=?
> permanent;
> rewrite ^/blogs/posts/([^/.]+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1?  permanent;
> rewrite ^/blogs/posts/?$  /blogs.php?action=show_member_blog&ownerName=?
> permanent;
> rewrite ^/blogs/posts/([^/.]+)/(\d+)/(\d+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&page=$3&per_page=$2?
> permanent;
> rewrite ^/blogs/posts/([^/.]+)/category/([^/.]+)/(\d+)/(\d+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&categoryUri=$2&page=$4&per_p
> age=$3?  permanent;
> 
> rewrite ^/events/?$  /events.php?show_events=all&action=show?  permanent;
> rewrite ^/events/all/(\d+)/(\d+)/?$
> /events.php?show_events=all&action=show&page=$2&per_page=$1?  permanent;
> rewrite ^/events/part/?$  /events.php?show_events=all&action=show?
> permanent;
> rewrite ^/events/search/?$  /events.php?action=search?  permanent;
> rewrite ^/events/search/([^/.]+)/?$
> /events.php?action=search_by_tag&tagKey=$1?  permanent;
> rewrite ^/events/my/?$  /events.php?action=show&show_events=my? 
> permanent;
> rewrite ^/events/new/?$  /events.php?action=new?  permanent;
> rewrite ^/events/entry/([^/.]+)/?$
> /events.php?action=show_info&eventUri=$1?  permanent;
> rewrite ^/events/part/([^/.]+)/?$ 
> /events.php?action=show_part&eventUri=$1?
> permanent;
>   
> rewrite ^/ads/?$  /classifieds.php?Browse=1?  permanent;
> rewrite ^/ads/search/?$  /classifieds.php?SearchForm=1?  permanent;
> rewrite ^/ads/my/?$  /classifiedsmy.php?MyAds=1?  permanent;
> rewrite ^/ads/new/?$  /classifiedsmy.php?PostAd=1?  permanent;
> rewrite ^/ads/cat/([^/.]+)/?$  /classifieds.php?catUri=$1?  permanent;
> rewrite ^/ads/all/cat/(\d+)/(\d+)/([^/.]+)/?$
> /classifieds.php?catUri=$3&page=$2&per_page=$1?  permanent;
> rewrite ^/ads/subcat/([^/.]+)/?$  /classifieds.php?scatUri=$1?  permanent;
> rewrite ^/ads/all/subcat/(\d+)/(\d+)/([^/.]+)/?$
> /classifieds.php?scatUri=$3&page=$2&per_page=$1?  permanent;
> rewrite ^/ads/entry/([^/.]+)/?$  /classifieds.php?entryUri=$1?  permanent;
> rewrite ^/ads/tag/([^/.]+)/?$  /classifieds_tags.php?tag=$1?  permanent;
>   
> rewrite ^/photo/all/(\d+)/(\d+)/?$  /browsePhoto.php?page=$2&per_page=$1?
> permanent;
> rewrite ^/photo/gallery_top/?$  /browsePhoto.php?rate=top?  permanent;
> rewrite ^/photo/gallery_top/(\d+)/(\d+)/?$
> /browsePhoto.php?rate=top&page=$2&per_page=$1?  permanent;
> rewrite ^/photo/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browsePhoto.php?tag=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/photo/gallery_tag/([^/.]+)/?$  /browsePhoto.php?tag=$1?
> permanent;
> rewrite ^/photo/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browsePhoto.php?ownerName=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/photo/gallery/all/([^/.]+)/?$  /browsePhoto.php?ownerName=$1?
> permanent;
> rewrite ^/photo/gallery/([^/.]+)/?$  /viewPhoto.php?fileUri=$1? 
> permanent;
> rewrite ^/photo/gallery/?$  /viewPhoto.php?fileUri=$1?  permanent;
>   
> rewrite ^/music/all/(\d+)/(\d+)/?$  /browseMusic.php?page=$2&per_page=$1?
> permanent;
> rewrite ^/music/gallery_top/?$  /browseMusic.php?rate=top?  permanent;
> rewrite ^/music/gallery_top/(\d+)/(\d+)/?$
> /browseMusic.php?rate=top&page=$2&per_page=$1?  permanent;
> rewrite ^/music/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browseMusic.php?tag=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/music/gallery_tag/([^/.]+)/?$  /browseMusic.php?tag=$1?
> permanent;
> rewrite ^/music/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browseMusic.php?ownerName=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/music/gallery/all/([^/.]+)/?$  /browseMusic.php?ownerName=$1?
> permanent;
> rewrite ^/music/gallery/([^/.]+)/?$  /viewMusic.php?fileUri=$1? 
> permanent;
> rewrite ^/music/gallery/?$  /viewMusic.php?fileUri=$1?  permanent;
>   
> rewrite ^/video/all/(\d+)/(\d+)/?$  /browseVideo.php?page=$2&per_page=$1?
> permanent;
> rewrite ^/video/gallery_top/?$  /browseVideo.php?rate=top?  permanent;
> rewrite ^/video/gallery_top/(\d+)/(\d+)/?$
> /browseVideo.php?rate=top&page=$2&per_page=$1?  permanent;
> rewrite ^/video/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browseVideo.php?tag=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/video/gallery_tag/([^/.]+)/?$  /browseVideo.php?tag=$1?
> permanent;
> rewrite ^/video/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browseVideo.php?ownerName=$1&page=$3&per_page=$2?  permanent;
> rewrite ^/video/gallery/all/([^/.]+)/?$  /browseVideo.php?ownerName=$1?
> permanent;
> rewrite ^/video/gallery/([^/.]+)/?$  /viewVideo.php?fileUri=$1? 
> permanent;
> rewrite ^/video/gallery/?$  /viewVideo.php?fileUri=$1?  permanent;
>   
> rewrite ^/groups/all/?$  /grp.php  permanent;
> rewrite ^/groups/entry/([^/.]+)/?$  /grp.php?action=group&groupUri=$1?
> permanent;
> rewrite ^/groups/category/([^/.]+)/?$  /grp.php?action=categ&categUri=$1?
> permanent;
> rewrite ^/groups/keyword/([^/.]+)/?$  /grp.php?action=categ&keyword=$1?
> permanent;
>   
> rewrite ^/search/tag/([^/.]+)/?$  /search.php?Tags=$1  permanent;
> --------------------------
> 
> 
> Maybe using location is better?:
> --------------------------
> location /articles/ {
>   rewrite ^/articles/?$ /articles.php;
>   rewrite ^/articles/([^/.]+)/?$
> /articles.php?action=viewarticle&articleUri=$1?;
>   rewrite ^/articles/category/([^/.]+)/?$
> /articles.php?action=viewcategory&articleCatUri=$1?;
> }
> 
> location /news/ {
>   rewrite ^/news/?$ /news.php;
>   rewrite ^/news/([^/.]+)/?$ /news.php?newsUri=$1?;
> }
> 
> location /blogs/ {
>   rewrite ^/blogs/?$ /blogs.php;
>   rewrite ^/blogs/all/(\d+)/(\d+)/?$ /blogs.php?page=$2&per_page=$1?;
>   rewrite ^/blogs/top/?$ /blogs.php?action=top_blogs?;
>   rewrite ^/blogs/top/(\d+)/(\d+)/?$
> /blogs.php?action=top_blogs&page=$2&per_page=$1?;
>   rewrite ^/blogs/top_posts/?$ /blogs.php?action=top_posts?;
>   rewrite ^/blogs/tag/([^/.]+)/?$
> /blogs.php?action=search_by_tag&tagKey=$1?;
>   rewrite ^/blogs/tag/?$ /blogs.php?action=search_by_tag&tagKey=?;
>   rewrite ^/blogs/posts/([^/.]+)/tag/([^/.]+)/?$
> /blogs.php?action=search_by_tag&tagKey=$2&ownerName=$1?;
>   rewrite ^/blogs/posts/([^/.]+)/category/([^/.]+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&categoryUri=$2?;
>   rewrite ^/blogs/entry/([^/.]+)/?$
> /blogs.php?action=show_member_post&postUri=$1?;
>   rewrite ^/blogs/entry/?$ /blogs.php?action=show_member_post&postUri=?;
>   rewrite ^/blogs/posts/([^/.]+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1?;
>   rewrite ^/blogs/posts/?$ /blogs.php?action=show_member_blog&ownerName=?;
>   rewrite ^/blogs/posts/([^/.]+)/(\d+)/(\d+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&page=$3&per_page=$2?;
>   rewrite ^/blogs/posts/([^/.]+)/category/([^/.]+)/(\d+)/(\d+)/?$
> /blogs.php?action=show_member_blog&ownerName=$1&categoryUri=$2&page=$4&per_p
> age=$3?;
> }
> 
> location /events/ {
>   rewrite ^/events/?$ /events.php?show_events=all&action=show?;
>   rewrite ^/events/all/(\d+)/(\d+)/?$
> /events.php?show_events=all&action=show&page=$2&per_page=$1?;
>   rewrite ^/events/part/?$ /events.php?show_events=all&action=show?;
>   rewrite ^/events/search/?$ /events.php?action=search?;
>   rewrite ^/events/search/([^/.]+)/?$
> /events.php?action=search_by_tag&tagKey=$1?;
>   rewrite ^/events/my/?$ /events.php?action=show&show_events=my?;
>   rewrite ^/events/new/?$ /events.php?action=new?;
>   rewrite ^/events/entry/([^/.]+)/?$
> /events.php?action=show_info&eventUri=$1?;
>   rewrite ^/events/part/([^/.]+)/?$
> /events.php?action=show_part&eventUri=$1?;
> }
> 
> location /ads/ {
>   rewrite ^/ads/?$ /classifieds.php?Browse=1?;
>   rewrite ^/ads/search/?$ /classifieds.php?SearchForm=1?;
>   rewrite ^/ads/my/?$ /classifiedsmy.php?MyAds=1?;
>   rewrite ^/ads/new/?$ /classifiedsmy.php?PostAd=1?;
>   rewrite ^/ads/cat/([^/.]+)/?$ /classifieds.php?catUri=$1?;
>   rewrite ^/ads/all/cat/(\d+)/(\d+)/([^/.]+)/?$
> /classifieds.php?catUri=$3&page=$2&per_page=$1?;
>   rewrite ^/ads/subcat/([^/.]+)/?$ /classifieds.php?scatUri=$1?;
>   rewrite ^/ads/all/subcat/(\d+)/(\d+)/([^/.]+)/?$
> /classifieds.php?scatUri=$3&page=$2&per_page=$1?;
>   rewrite ^/ads/entry/([^/.]+)/?$ /classifieds.php?entryUri=$1?;
>   rewrite ^/ads/tag/([^/.]+)/?$ /classifieds_tags.php?tag=$1?;
> }
> 
> location /photo/ {
>   rewrite ^/photo/all/(\d+)/(\d+)/?$
> /browsePhoto.php?page=$2&per_page=$1?;
>   rewrite ^/photo/gallery_top/?$ /browsePhoto.php?rate=top?;
>   rewrite ^/photo/gallery_top/(\d+)/(\d+)/?$
> /browsePhoto.php?rate=top&page=$2&per_page=$1?;
>   rewrite ^/photo/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browsePhoto.php?tag=$1&page=$3&per_page=$2?;
>   rewrite ^/photo/gallery_tag/([^/.]+)/?$ /browsePhoto.php?tag=$1?;
>   rewrite ^/photo/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browsePhoto.php?ownerName=$1&page=$3&per_page=$2?;
>   rewrite ^/photo/gallery/all/([^/.]+)/?$ /browsePhoto.php?ownerName=$1?;
>   rewrite ^/photo/gallery/([^/.]+)/?$ /viewPhoto.php?fileUri=$1?;
>   rewrite ^/photo/gallery/?$ /viewPhoto.php?fileUri=$1?;
> }
> 
> location /music/ {
>   rewrite ^/music/all/(\d+)/(\d+)/?$
> /browseMusic.php?page=$2&per_page=$1?;
>   rewrite ^/music/gallery_top/?$ /browseMusic.php?rate=top?;
>   rewrite ^/music/gallery_top/(\d+)/(\d+)/?$
> /browseMusic.php?rate=top&page=$2&per_page=$1?;
>   rewrite ^/music/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browseMusic.php?tag=$1&page=$3&per_page=$2?;
>   rewrite ^/music/gallery_tag/([^/.]+)/?$ /browseMusic.php?tag=$1?;
>   rewrite ^/music/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browseMusic.php?ownerName=$1&page=$3&per_page=$2?;
>   rewrite ^/music/gallery/all/([^/.]+)/?$ /browseMusic.php?ownerName=$1?;
>   rewrite ^/music/gallery/([^/.]+)/?$ /viewMusic.php?fileUri=$1?;
>   rewrite ^/music/gallery/?$ /viewMusic.php?fileUri=$1?;
> }
> 
> location /video/ {
>   rewrite ^/video/all/(\d+)/(\d+)/?$
> /browseVideo.php?page=$2&per_page=$1?;
>   rewrite ^/video/gallery_top/?$ /browseVideo.php?rate=top?;
>   rewrite ^/video/gallery_top/(\d+)/(\d+)/?$
> /browseVideo.php?rate=top&page=$2&per_page=$1?;
>   rewrite ^/video/gallery_tag/([^/.]+)/(\d+)/(\d+)/?$
> /browseVideo.php?tag=$1&page=$3&per_page=$2?;
>   rewrite ^/video/gallery_tag/([^/.]+)/?$ /browseVideo.php?tag=$1?;
>   rewrite ^/video/gallery/all/([^/.]+)/(\d+)/(\d+)/?$
> /browseVideo.php?ownerName=$1&page=$3&per_page=$2?;
>   rewrite ^/video/gallery/all/([^/.]+)/?$ /browseVideo.php?ownerName=$1?;
>   rewrite ^/video/gallery/([^/.]+)/?$ /viewVideo.php?fileUri=$1?;
>   rewrite ^/video/gallery/?$ /viewVideo.php?fileUri=$1?;
> }
> 
> location /groups/ {
>   rewrite ^/groups/all/?$ /grp.php;
>   rewrite ^/groups/entry/([^/.]+)/?$ /grp.php?action=group&groupUri=$1?;
>   rewrite ^/groups/category/([^/.]+)/?$
> /grp.php?action=categ&categUri=$1?;
>   rewrite ^/groups/keyword/([^/.]+)/?$ /grp.php?action=categ&keyword=$1?;
> }
> 
> location /search/tag/ {
>   rewrite ^/search/tag/([^/.]+)/?$ /search.php?Tags=$1?;
> }
> 
> location  /  {
>   try_files $uri $uri/ /profile.php?ID=$uri;
> }
> --------------------------
> 
> 
> 
> > 
> > RewriteCond %{REQUEST_FILENAME} -f [OR]
> > RewriteCond %{REQUEST_FILENAME} -d
> > RewriteRule .+ - [L]
> > RewriteRule ^([A-Za-z0-9_-]+)$ profile.php?ID=$1 [QSA,L]
> > 
> Those here could be done with a try rule. Something like:
> --------------------------
> location  /  {
>   try_files  $uri $uri/ /profile.php?ID=$uri;
> }
> --------------------------
> 
> Or:
> --------------------------
> location  /  {
>   if (-e $request_filename) {
>     set $ampr01 1;
>   }
>   if ($request_filename ~* "^([A-Za-z0-9_-]+)$") {
>     set $ampr02 1;
>   }
>   if ($ampr01$ampr02 = "11") {
>     rewrite ^/([A-Za-z0-9_-]+)$  /profile.php?ID=$1  last;
>     break;
>   }
> }
> --------------------------
> 
> 
> I have not tested those rules. I don't know if they work.
> 
> 
> > Regards, 
> > 
> Kind Regards,
> 
> > -Team AMP 
> > 
> Steve
> 
> 
> > http://www.ampprod.com 
> > 
> 
> -- 
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
> 
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx

-- 
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02



More information about the nginx mailing list