Understand and Enable Search Engine Friendly (SEF) in Joomla

Search Engine Friendly(SEF) also known as human readable URL. With the most famous Web Service like Nginx, Apache and IIS7, they do support URL rewrite or mod_rewrite to rewrite the human readable URL such as www.domain.com/about instead of www.domain.com/about.html.

With Joomla 1.5 and above, Joomla come with 3 option from your Global Configuration.
–  Search Engine Friendly URLs – With this option enabled, SEF will enable and your URL will look like, http://www.example.com/index.php/the-­news/1-­latest­-news/1­-welcome­-to­-joomla.
– Use Apache mod_rewrite/URL rewriting – With this option enabled, mod_rewrite will eliminate inde.php and your URL will look like, http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla
– Add suffix to URLs – With this option enabled, your URL will added .html at the end of the URL and it will look like http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla.html

Nginx
To enable SEF with Nginx, add the following line to your (vhost)nginx.conf file.

# Support Clean (aka Search Engine Friendly) URLs</tt>
        location / {
                try_files $uri $uri/ /index.php?q=$request_uri;
        }

Apache
To enable SEF with Apache server, you may easily rename the htaccess.txt to .htaccess file. This step is not necessary as you may get your .htaccess file generated if it is install in  own folder.

IIS 7
With IIS 7, you may choose to use GUI or directly add it from web.config file.

With GUI interface, you may add the following option from the URL rewrite option.

Pattern field: ^([^/]+)/?$
Ignore case ON
Action type: Rewrite
Rewrite URL: index.php/

 Otherwise, you may add the following line to your web.config file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Common Exploit Blocking" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" />
                        <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" />
                        <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" />
                    </conditions>
                    <action type="Redirect" url="index.php" appendQueryString="false" redirectType="SeeOther" />
                </rule>
                <rule name="Joomla Search Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
                </rule>
                <rule name="Joomla Main Rewrite Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="(/[^.]*|\.(php|html?|feed|pdf|raw))$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/" />
                </rule>
            </rules>
        </rewrite>
        <caching>
            <profiles>
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            </profiles>
        </caching>
    </system.webServer>
</configuration>

Block WordPress spam comment with .htaccess

If you have self hosted WordPress and always got lots of spam comment, you may actually blocked them through your .htaccess file.

The source code as below was get from AllGuru.Net,

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*xyz.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Open the .htaccess file and place the code as above then you shall be able to filter the spam automatically.

Prevent SQL injection by using IIS URL Rewrite

Nowadays, a bad or unoptimizes SQL query could easily compromised or get attacked. However you may try to reduce or prevent (Don’t say avoid, it is not possible, keke) the SQL injection through your expression rules.

If you are using IIS as your web engine, you may use some expression to reduce the SQL injection.

[dD][\%]*[eE][\%]*[cC][\%]*[lL][\%]*[aA][\%]*[rR][\%]*[eE][\s\S]*[@][a-zA-Z0-9_]+[\s\S]*[nN]*[\%]*[vV][\%]*[aA][\%]*[rR][\%]*[cC][\%]*[hH][\%]*[aA][\%]*[rR][\s\S]*[eE][\%]*[xX][\%]*[eE][\%]*[cC][\s\S]*

Continue reading Prevent SQL injection by using IIS URL Rewrite

enable HTTP Compression

Many of the website did teach how to check HTTP Compression, what Apache module is needed, but there are less guide on how to make it done.

Today, Mick Genie will guide you how to make it done.

Firstly, you may need to compile your Apache with mod_gzip and mod_deflate (Actually Apache 1.x needed mod_gzip and Apache 2.x needed mod_deflate, hence you may compile both of them).

Once done, modify your httpd.conf and assume it is located in /usr/local/apache/conf. Add the following line to the configuration file.

<Location />
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI  \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
</Location>

Restart the httpd services.

service httpd restart

The above command from httpd.conf will compress all the files except the .gif, .jpe, .jpeg and .png files.

Ruby on Rails Handy Guide

Some Useful command
To install ruby Gem,
gem install [gem_name]
eg, gem install rails

To install ruby Gem with certain version,
gem install [gem_name] –version=x.x.x
eg, gem install rails –version=2.3.5
eg, gem install rails -v=2.3.5

To update ruby Gem,
gem update [gem_name]
eg, gem update mysql

To update ruby Gem with latest version(for all)
gem update –system

To check missing gem
rake gems:install (must run from rails apps folder)

To install gem with lesser space
gem install –no-rdoc –no-ri [gem_name]
eg. gem install –no-rdoc –no-ri rails

To check RoR log,
Path: /home/[cpanel_username]/etc/rails_apps/[apps_name]/log

Continue reading Ruby on Rails Handy Guide