# SEO Friendly Urls

**URL:** <https://www.ruby-forum.com/t/seo-friendly-urls/217524>\
**Category:** NGINX\
**Created:** [March 4, 2012, 2:31am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524 "2012-03-04T02:31:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 4, 2012, 2:31am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/1 "2012-03-04T02:31:14Z")

</div>

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/](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?

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 3:34am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/2 "2012-03-04T03:34:16Z")

</div>

On Sat, 2012-03-03 at 20:30 -0500, adam estes wrote:

> I’m trying to get the nginx to recognize that index.php/login is  
> 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

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 4:28am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/3 "2012-03-04T04:28:01Z")

</div>

Aha! That did it 🙂

Thank you.

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:19am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/4 "2012-03-04T06:19:32Z")

</div>

Actually, that fixed -most- of it. Butttt

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

Gives a 404 not found ☹

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:23am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/5 "2012-03-04T06:23:50Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

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

location ~ .php$ {

should be:

location ~ .php($|/) {

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:34am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/6 "2012-03-04T06:34:19Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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 {

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:38am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/7 "2012-03-04T06:38:39Z")

</div>

Still giving the same thing ☹

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:28am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/8 "2012-03-04T06:28:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:42am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/9 "2012-03-04T06:42:21Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Still giving the same thing ☹

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

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:04am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/10 "2012-03-04T07:04:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:07am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/11 "2012-03-04T07:07:00Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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?

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 6:48am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/12 "2012-03-04T06:48:31Z")

</div>

> **[server { listen 80; server\_name xxxxxx -...](https://pastebin.com/3uz4tCmd)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:08am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/13 "2012-03-04T07:08:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:13am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/14 "2012-03-04T07:13:47Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> The error comes from nginx

What’s in error log?

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:27am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/15 "2012-03-04T07:27:21Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](http://domain.us), request: “GET$  
> /FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f  
> HTTP/1.1”, host: “[domain.us](http://domain.us)”

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

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:27am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/16 "2012-03-04T07:27:58Z")

</div>

Right now its .php

It had the $ before and still gave the error.

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:17am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/17 "2012-03-04T07:17:30Z")

</div>

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](http://domain.us), request: “GET$  
/FG152/index.php/cron/graburls/999182b003023a35c327db371a74a85f  
HTTP/1.1”, host: “[domain.us](http://domain.us)”

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:37am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/18 "2012-03-04T07:37:50Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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;  
}

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:40am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/19 "2012-03-04T07:40:55Z")

</div>

returns 503

---

<div class="post-metadata">

**Author:** ![adam\_estes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@adam\_estes](https://www.ruby-forum.com/u/adam_estes)\
**Post date:** [March 4, 2012, 7:58am UTC](https://www.ruby-forum.com/t/seo-friendly-urls/217524/20 "2012-03-04T07:58:48Z")

</div>

2012/3/4 adam estes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> returns 503

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

[Next page](https://www.ruby-forum.com/t/seo-friendly-urls/217524.md?page=2)
