Home > Joomla > Joomla! 在 Nginx 环境下的 URL 优化

Joomla! 在 Nginx 环境下的 URL 优化

December 29th, 2011

本文解决以下几个问题:

1、在 Nginx 环境下移除页面及 URL 中的 index.php

2、在 Apache 环境下移除页面及 URL 中的 index.php

3、如何在所有的 URL 后加上 .html 后缀,实现伪静态

示例:

http://www.yoursite.com/index.php/category/article

=>http://www.yoursite.com/category/article.html

1、Nginx 环境:
首先进行 nginx.conf 配置

server {
        listen 80;
        server_name YOUR_DOMAIN;
        server_name_in_redirect off;

        access_log /var/log/nginx/localhost.access_log main;
        error_log /var/log/nginx/localhost.error_log info;

        root PATH_ON_SERVER;
        index index.php;
        # Support Clean (aka Search Engine Friendly) URLs
        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        index index.php index.html index.htm default.html default.htm;
        # deny running scripts inside writable directories
        location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
                return 403;
                error_page 403 /403_error.html;
        }

        location ~ .*.php$ {
            include /etc/nginx/fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        # caching of files
        location ~* \.(ico|pdf|flv)$ {
                expires 1y;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
                expires 14d;
        }

}

然后在joomla 后台更改网站全局设置
>site>Global Configuration>
Search Engine Friendly URLs (YES)
Use URL rewriting (YES)

2、 Apache 环境

首先在joomla 后台更改网站全局设置
>site>Global Configuration>
Search Engine Friendly URLs (YES)
Use URL rewriting (YES)

然后找到网站根目录 htaccess.txt 文件,重命名为 .htaccess

最后找到 .htaccess 文件中 # RewriteBase / ,去掉“#” 。

3、实现伪静态

>site>Global Configuration>
Adds Suffix to URL (YES) ,这个是在所有的网页后面加上友好的 .html 后缀的。

admin Joomla

Comments are closed.