Short URL question

als56k

Joined: 2006-04-22
Posts: 24
Posted: Thu, 2009-10-15 22:42

Where in the code are the short URLs generated?

I know that mod_rewrite translates user requests for e.g. "http://www.example.com/gallery3/album/image" into "http://www.example.com/gallery3/index.php?..." But mod_rewrite doesn't generate the links that appear on pages generated by G3. So where does G3 generate the link to "/album/image" instead of "/index.php?..."?

Background: Trying to get G3 to work with non-Apache web server. Not asking for any help with the hacking itself, but I've read the docs and grepped the code for about everything I can think of and can't figure out where those URLs are coming from.

Many thanks,
als56k

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Thu, 2009-10-15 22:50

Nothing in the code, it's very simple with G3. Just uncomment some rewrite rules in the .htaccess that ships with G3.

What web server? Someone may have already done it :)

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
als56k

Joined: 2006-04-22
Posts: 24
Posted: Thu, 2009-10-15 23:02

Nginx, and as far as I know no one has done it.

I understand how to activate short URLs when using Apache by uncommenting the mod_rewrite stanza in .htaccess. But mod_rewrite just rewrites URLs; it doesn't rewrite the content of the page. Or does it?

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Thu, 2009-10-15 23:20

The URLs in the page are relative, not absolute, so there's no changing of the content needed. Just activate the rewrite rules and you're done.

When they are not active, index.php is used and put into the URLs in the page, when they are active, index.php is not put into the URLs in the page and doesn't show up.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
als56k

Joined: 2006-04-22
Posts: 24
Posted: Thu, 2009-10-15 23:41

Many thanks, nivekiam. I appreciate the time taken to explain it to me.

I assume when you say that "index.php is...put into the URLs in the page," you mean that G3 knows that the mod_rewrite rules are not active and so G3 inserts index.php into the URLs. If I understand you correctly, where in G3 is this decision made? And where is the actual inserting done?

Background follows, if it is useful or interesting:

The problem on nginx is that index.php is inserted into the URLs in the page even when rewrite rules are active. I think this is for one of two reasons: (1) G3 can't tell that the rewrite rules are active, because nginx puts them in a different place from Apache and/or G3's mod_rewrite test fails, or (2) nginx reports some server environment variables differently from Apache. (The problem variables are REQUEST_URI, SCRIPT_NAME, PHP_SELF. For the URL "/index.php/album", nginx reports them as "/index.php/album"; Apache reports them as "/index.php".)

 
als56k

Joined: 2006-04-22
Posts: 24
Posted: Thu, 2009-10-15 23:55

Okay, got it, I think: The index.php is prepended to the url in /system/helpers/url.php. I think I can follow the trail back up from there. Thanks a lot for your help.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Fri, 2009-10-16 00:00
Quote:
you mean that G3 knows that the mod_rewrite rules are not active and so G3 inserts index.php into the URLs.

No, there is NOTHING in G3 that knows this. If rewrite rules are active, you access G3 through www.example.com/gallery3/ and your URLs would look like /gallery3/var/thumbs/41.jpg for the thumbnail image of the image named 41.jpg

If you don't have rewrite rules active, you access G3 through www.example.com/gallery3/index.php and your URLs will have index.php in them.

You're thinking way to hard about this :)

Just figure out how to translate the Apache rewrite rules that ship with G3 for Nginx and it'll just work. No modification to G3 necessary.

Quote:
The problem on nginx is that index.php is inserted into the URLs in the page even when rewrite rules are active.

Ah, that sounds like a problem with Nginx. There is nothing in G3 doing this. It puts index.php in the URL if it's accessed by a URL with index.php in there. Again, G3 uses relative URLs.

I've gotten this working on Lighttpd. For normal navigation, there is no mod_rewrite test in G3. Only when you go to set permissions does it check if rewriting it enabled and working (as it should from Apache). Do you or have you restarted Nginx after making the changes?

I've seen a post or two about Lighttpd and maybe Nginx, I'll see if I can dig them up, they might have been conversations in IRC too....
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
als56k

Joined: 2006-04-22
Posts: 24
Posted: Fri, 2009-10-16 00:20

Strange. If I access the site at "http://www.example.com/g3/", all the relative links generated by G3 point to e.g. "/g3/index.php/album". However rewrite rules are active and working, because I can access the album directly by typing "http://www.example.com/g3/album" into my browser bar.

I've corresponded with someone else who couldn't get it to work on nginx and ended up proxying G3 requests to Apache. But it's good to know that you got it working on lighttpd, as if I have to run G3 on a second server I'd rather use lighttpd than Apache.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Fri, 2009-10-16 16:08

I was looking at what I did for Lighttpd again and it looks like I really only got as far as fooling the system that rewriting was working to get rid of the warning when you edit permissions. NOTE: to do this, you'll also need to change another file to change the string, HTTP/1.1 to HTTP/1.0

I think that was access.php, but I'd have to double check.

Could you post the Nginx rewrite rules you've tried so far?
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
als56k

Joined: 2006-04-22
Posts: 24
Posted: Sat, 2009-10-17 16:08

Here's the Nginx rewrite rule, for an installation at /path/to/home/gallery3:

location ~ /gallery3/ {
root /path/to/home;
index index.html index.php;
if (!-e $request_filename) {
rewrite ^/gallery3/(.*)$ /gallery3/index.php?kohana_uri=$1 last;
}
}

Here's my assessment of how URLs are generated, along with a temporary kludge for Nginx:

1. URL is inserted into page by $child->url() in /themes/default/views/album.html.php
2. This calls public function url() in /modules/gallery/models/item.php
3. The url() function calls two things:
(a) public function relative_url() in item.php. This gets the "relative URL" (e.g., /album/photo) from the database.
(b) public function site() in /system/helpers/url.php
4. The site() function calls public function base() in url.php. The first argument to base() is a boolean variable, set to TRUE at #3b above, that tells base() to insert the value of the config variable index_page into the URL.
5. The base() function calls Kohana::config('core.index_page')
6. This then gets the value of index_page from the following line in /application/config/config.php
$config["index_page"] = isset($_GET["kohana_uri"]) ? "" : "index.php";

So the problem would seem to be that isset($_GET["kohana_uri"]) returns TRUE under Apache but (for whatever reason) FALSE under Nginx. And indeed Nginx can be fooled into leaving out the index.php by changing the else phrase from "index.php" to ""; then everything works as expected.

This is not exactly a solution--and it may break something else I haven't yet discovered--but it also might work as a temporary kludge.

 
Kovu

Joined: 2010-10-20
Posts: 3
Posted: Wed, 2010-10-20 19:24

G3 start working at my site with this config (many thanks to my administrator - lion):

server {
        listen       80;
        server_name  blablabla.ru gallery.lololo.ru;

        client_max_body_size 128M;

        index index.php;

        location / {

            if (!-f $request_filename) {
                rewrite ^/gallery3/index.php/(.+)$ /gallery3/index.php?kohana_uri=$1 last;
                rewrite ^/gallery3/(.+)$ /gallery3/index.php?kohana_uri=$1 last;
                rewrite ^/gallery3/$ /gallery3/index.php?kohana_uri=/ last;
            }

            expires max;
            root   /home2/bububu/public_html/lololo.ru;
        }
        location ~ \.php(.*)$ {
            root           /home2/bububu/public_html/lololo.ru;
            fastcgi_pass   127.0.0.1:9016;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param  SCRIPT_FILENAME  /home2/bububu/public_html/lololo.ru/$fastcgi_script_name;
            fastcgi_param  PATH_INFO        $fastcgi_path_info;
            include        fastcgi_params;
        }
    }

G3 as compared with G2 has very few functions and lots of requirements, and so I will continue using G2. G3 is very very useless at the present time.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7934
Posted: Tue, 2010-10-26 03:26

"very very useless at the present time". thanks, buddy -- you're making a lot of friends here.

If there's something you want, ask for it.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git

 
viulian

Joined: 2008-08-26
Posts: 4
Posted: Thu, 2010-10-28 21:22

I just installed gallery3 and I must say that I am impressed. A much better looking gallery than gallery2 - this is for sure.

1) My first problem was that I don't host it under http://example.com/gallery3 but under http://example.com/a/gallery3.
And nothing basically worked - I only saw the text - no images / js / css loaded.
While checking the helpers/url.php I realized that the base might not be computed properly (as Firebug showed that http://example.com/lib/file... was accessed, instead of http://example.com/a/gallery3/lib/file...).

Went to config.php and saw that site_domain computation looked impressive. Commented it out and put correct value:


$conf["site_domain"]="/a/gallery3"

A suggestion here might be to do this detection at install time, let the user change it if he/she wants, and then stamp it there directly, instead of the detection logic ?

2) Second problem was the nginx rules, which, needed some adjustments as gallery3 is one level deep (I took my g2 rules and addapted)

                location /a/gallery3 {
                        index index.php;
                        if (!-e $request_filename) {
                                rewrite ^/a/gallery3/index.php/(.*)$ /a/gallery3/$1 last;
                                rewrite ^/a/gallery3/(.*)$ /a/gallery3/index.php?kohana_uri=$1 last;
                        }
                }

3) I used the advice of als56k and set index_page to empty too.

Now everything works perfect!

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7934
Posted: Sun, 2010-10-31 19:05

It would be more efficient to do the computation once, but then we run into the problem that users who refer to their site with multiple different urls (eg: www.example.com vs. example.com vs something else that works) wind up with a site that's broken in subtle ways). Also it means that if you move the site around it doesn't work and is confusing. The detection logic gives us one less configuration option which makes life easier for almost all folks.

The detection logic isn't working for you because you're on nginx which is an unsupported platform; nginx does things differently than Apache2 and (probably) requires different detection logic. It's not a problem, but it's also something that we're not aggressively trying to resolve.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git