SEO Friendly Urls

54 views
Skip to first unread message

adam estes

unread,
Mar 3, 2012, 8:30:35 PM3/3/12
to ng...@nginx.org
I'm attempting to use Nginx to server a CodeIgniter Script.

Code Igniter uses SEO Friendly scripts (AKA, only uses / instead of ?)

This works fine when I try and use it on Apache. Trying to setup my
own VPS with Code Igniter through NGINX only leans to a pain.

The server is setup with the base folder being a phpbb form, and a
codeigniter script in the folder /fg152/

I'm trying to get the nginx to recognize that index.php/login is
supposed to be a query for code igniter, not a file of its own.

I tried every configuration on this link.

http://codeigniter.com/forums/viewthread/90231/

My current Nginx conf looks like this.


location /fg152/ {
root /home/sites/domain/fg152/;
index index.php;
try_files $uri $uri/ /fg152/index.php;

}


location / {
root /home/sites/domain/;
index index.php index.html index.htm;
# PHPBB SEO REWRITE RULES - ADVANCED
# AUTHOR : dcz www.phpbb-seo.com
# STARTED : 01/2006

rewrite
^/(forum|[a-z0-9_-]*-f)([0-9]+)/?(page([0-9]+)\.html)?$
/viewforum.php?f=$2&start=$4 last;
rewrite
^/(forum|[a-z0-9_-]*-f)([0-9]+)/(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$
/viewtopic.php?f=$2&t=$4&start=$6 last;
rewrite
^/([a-z0-9_-]*)/?(topic|[a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$
/viewtopic.php?forum_uri=$1&t=$3&start=$5 last;
rewrite
^/resources/[a-z0-9_-]+/(thumb/)?([0-9]+)$
/download/file.php?id=$2&t=$1 last;
rewrite ^/member/([^/]+)/?$
/memberlist.php?mode=viewprofile&un=$1 last;
rewrite
^/member/([^/]+)/(topics|posts)/?(page([0-9]+)\.html)?$
/search.php?author=$1&sr=$2&start=$4 last;
rewrite
^/(group|[a-z0-9_-]*-g)([0-9]+)(-([0-9]+))?\.html$
/memberlist.php?mode=group&g=$2&start=$4 last;
rewrite ^/post([0-9]+)\.html$ /viewtopic.php?p=$1 last;
rewrite ^/active-topics(-([0-9]+))?\.html$
/search.php?search_id=active_topics&start=$2&sr=topics last;
rewrite ^/unanswered(-([0-9]+))?\.html$
/search.php?search_id=unanswered&start=$2&sr=topics last;
rewrite ^/newposts(-([0-9]+))?\.html$
/search.php?search_id=newposts&start=$2&sr=topics last;
rewrite ^/unreadposts(-([0-9]+))?\.html$
/search.php?search_id=unreadposts&start=$2 last;
rewrite ^/the-team\.html$
/memberlist.php?mode=leaders last;
rewrite
^/([a-z0-9_-]+)/?(page([0-9]+)\.html)?$
/viewforum.php?forum_uri=$1&start=$3 last;
rewrite
^/.+/(style\.php|ucp\.php|mcp\.php|faq\.php|download/file.php)$ /$1
last;
if (!-e $request_filename) {
rewrite
^/([a-z0-9_/-]+)/?(page([0-9]+)\.html)?$
/viewforum.php?forum_uri=$1&start=$3 last;
break;
}
# END PHPBB PAGES
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# A handy function that became available in 0.7.31 that breaks down
# The path information based on the provided regex expression
# This is handy for requests such as file.php/some/paths/here/

fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED
$document_root$fastcgi_path_info;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass unix:/etc/phpcgi/php-cgi.socket;
fastcgi_index index.php;
}


Now. This lets the script work. Instead of giving 404 on
/fg152/index.php/login it shows the login page. EXCEPT the images do
not log. Huge problem there.

The images are located at /fg152/application/views/images/

And the login.php that its calling is located at /fg152/application/controllers/

If I remove the location /fg152/ it will show up with the image files
again (But the rest gets a 404 error

I've tried using

location /fg152r/ {

if (-f $request_filename) {
expires max;
break;
}

if (!-e $request_filename) {
rewrite ^/fg152/(.*)$ /fg152/index.php/$1 last;
}
}

Still no luck. What can I do to resolve this issue and get both php
and image files working?

_______________________________________________
nginx mailing list
ng...@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Cliff Wells

unread,
Mar 3, 2012, 9:33:31 PM3/3/12
to ng...@nginx.org
On Sat, 2012-03-03 at 20:30 -0500, adam estes wrote:
> I'm attempting to use Nginx to server a CodeIgniter Script.
>
> Code Igniter uses SEO Friendly scripts (AKA, only uses / instead of ?)
>
> This works fine when I try and use it on Apache. Trying to setup my
> own VPS with Code Igniter through NGINX only leans to a pain.
>
> The server is setup with the base folder being a phpbb form, and a
> codeigniter script in the folder /fg152/
>
> I'm trying to get the nginx to recognize that index.php/login is
> supposed to be a query for code igniter, not a file of its own.
>
> I tried every configuration on this link.
>
> http://codeigniter.com/forums/viewthread/90231/
>
> My current Nginx conf looks like this.
>
>
> location /fg152/ {
> root /home/sites/domain/fg152/;
> index index.php;
> try_files $uri $uri/ /fg152/index.php;
>
> }

> The images are located at /fg152/application/views/images/


Try this instead:

location /fg152 {
root /home/sites/domain;


index index.php;
try_files $uri $uri/ /fg152/index.php;
}

Remember that the location is appended to the root, so your
configuration would lead to /home/sites/domain/fg152/fg152, which I
don't think is what you intended.

Regards,
Cliff

adam estes

unread,
Mar 3, 2012, 10:27:34 PM3/3/12
to ng...@nginx.org
Aha! That did it :)

Thank you.

adam estes

unread,
Mar 4, 2012, 12:18:53 AM3/4/12
to ng...@nginx.org
Actually, that fixed -most- of it. Butttt

FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f

Gives a 404 not found :(

Edho Arief

unread,
Mar 4, 2012, 12:22:52 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> Actually, that fixed -most- of it. Butttt
>
> FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f
>
> Gives a 404 not found :(
>

location ~ \.php$ {

should be:

location ~ \.php($|/) {

adam estes

unread,
Mar 4, 2012, 12:27:55 AM3/4/12
to ng...@nginx.org
That just broke things.

It provides No input file specified. when accessing any index.php
links in the /fg152 folder. Including just going to /fg152/index.php

Edho Arief

unread,
Mar 4, 2012, 12:33:30 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> That just broke things.
>
> It provides No input file specified. when accessing any index.php
> links in the /fg152 folder. Including just going to /fg152/index.php
>

Try this instead:

location ~ \.php {

adam estes

unread,
Mar 4, 2012, 12:38:21 AM3/4/12
to ng...@nginx.org
Still giving the same thing :(

Edho Arief

unread,
Mar 4, 2012, 12:41:17 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> Still giving the same thing :(
>

Can you send your current config? In pastebin instead of email.

adam estes

unread,
Mar 4, 2012, 12:47:49 AM3/4/12
to ng...@nginx.org

adam estes

unread,
Mar 4, 2012, 1:04:06 AM3/4/12
to ng...@nginx.org
To expand on this.

/FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f

This link tells index.php to load cron.php which then run the graburls
command which uses the cronkey (Which is the lost aug)

This returns a 404 with the current config.

Edho Arief

unread,
Mar 4, 2012, 1:06:03 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> To expand on this.
>
> /FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f
>
> This link tells index.php to load cron.php which then run the graburls
> command which uses the cronkey (Which is the lost aug)
>
> This returns a 404 with the current config.

Does the /fg512/index.php work? The 404 comes from nginx or php?

adam estes

unread,
Mar 4, 2012, 1:07:58 AM3/4/12
to ng...@nginx.org
Yes. The index.php does work. It also works with anything that doesn't
need multiple inputs

Such as

index.php/log
index.php/keywords

etc

The error comes from nginx

404 Not Found

nginx/1.0.5

Edho Arief

unread,
Mar 4, 2012, 1:12:56 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> Yes. The index.php does work. It also works with anything that doesn't
> need multiple inputs
>
> Such as
>
> index.php/log
> index.php/keywords
>
> etc
>
> The error comes from nginx
>

What's in error log?

adam estes

unread,
Mar 4, 2012, 1:17:03 AM3/4/12
to ng...@nginx.org
2012/03/04 01:15:30 [error] 7662#0: *36 open()
"/home/sites/domain/FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f"
failed (2: No such file or directory), client: 71.3.129.216, server:
domain.us, request: "GET$
/FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f
HTTP/1.1", host: "domain.us"

Edho Arief

unread,
Mar 4, 2012, 1:26:09 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> 2012/03/04 01:15:30 [error] 7662#0: *36 open()
> "/home/sites/domain/FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f"
> failed (2: No such file or directory), client: 71.3.129.216, server:
> domain.us, request: "GET$
> /FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f
> HTTP/1.1", host: "domain.us"
>
>

Is it with location ~ \.php or location ~\.php$ ?

adam estes

unread,
Mar 4, 2012, 1:27:46 AM3/4/12
to ng...@nginx.org
Right now its \.php

It had the $ before and still gave the error.

Edho Arief

unread,
Mar 4, 2012, 1:36:40 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> Right now its \.php
>
> It had the $ before and still gave the error.
>

Try reverting to \.php$ and add one more location block:

location ~ \.php/ {
return 503;

adam estes

unread,
Mar 4, 2012, 1:40:27 AM3/4/12
to ng...@nginx.org
returns 503

Edho Arief

unread,
Mar 4, 2012, 1:57:59 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:
> returns 503
>

Remove the php/ block and change php$ to php (location ~ \.php {)

adam estes

unread,
Mar 4, 2012, 2:01:11 AM3/4/12
to ng...@nginx.org
That puts us back to how we where before you had me add that block :P

Edho Arief

unread,
Mar 4, 2012, 7:07:14 AM3/4/12
to ng...@nginx.org
2012/3/4 adam estes <wty...@gmail.com>:

> That puts us back to how we where before you had me add that block :P
>

Since the error came from nginx, seems like you didn't reload the
config properly.

Francis Daly

unread,
Mar 4, 2012, 8:13:48 AM3/4/12
to ng...@nginx.org
On Sun, Mar 04, 2012 at 12:47:49AM -0500, adam estes wrote:

Hi there,

> http://pastebin.com/3uz4tCmd

If I've understood what you are trying to do, will

===
location ^~ /fg152 {
root /usr/local/domain;
index index.php index.html;
try_files $uri $uri/ /fg152/index.php;
location = /fg152/index.php {
include fastcgi.conf;
fastcgi_pass unix:/etc/phpcgi/php-cgi.socket;
}
}
===

fit the requirements?

You can probably move "root", "index", and "include" to server level,
if they are common to other locations.

Be aware that this effectively *removes* the /.ht and /.svn protection
config for this location hierarchy, so you'll want to either put them
back in, or (better) not have readable files in the web space that you
don't want served.

And if you try to access /fg152a, you might be a bit surprised -- but
that can be adjusted later if necessary.

f
--
Francis Daly fra...@daoine.org

Valentin V. Bartenev

unread,
Mar 4, 2012, 8:14:02 AM3/4/12
to ng...@nginx.org
On Sunday 04 March 2012 10:17:03 adam estes wrote:
> 2012/03/04 01:15:30 [error] 7662#0: *36 open()
> "/home/sites/domain/FG152/index.php/cron/graburls/999182b003023a35c327db371
> a74a85f" failed (2: No such file or directory), client: 71.3.129.216,
> server: domain.us, request: "GET$
> /FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f
> HTTP/1.1", host: "domain.us"
>

Just for your note, FG152 doesn't equal fg152.

wbr, Valentin V. Bartenev

adam estes

unread,
Mar 4, 2012, 9:56:56 PM3/4/12
to ng...@nginx.org
Now i feel kinda stupid. The project was named FG152 and the cron jobs
where generated with that url. I changed this later because of too
many issues with the pathing. I just didn't remember to change the
cron jobs :P
Reply all
Reply to author
Forward
0 new messages