How to remove the www from url with rewite rule

Now these days keeping www in URL is becoming old fashion. How can check many websites for that and the current example is twitter.com. Using apache rule you can remove the www from url with rewite rule.

How to remove the www from url with rewite rule

How to remove the www from url with rewite rule
How to remove the www from url with rewite rule

I specially dont like to put www in URL so we can easily remove the www from URL.

Open your apache configuration file. If you are using Linux then open file from following location

# vim /etc/httpd/conf/httpd.conf

put following lines in your virtual directory section.


# remove www from url
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301,L]

We can use this rewrite rule in .htaccess file also. But make sure .htaccess is enable through apache server.


# remove the www from URL.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*$ http://example.com%{REQUEST_URI} [R=301s,L]

For WordPress websites for seo purpose putting above lines in .htaccess file is really best. That will gives you the really great result in future.

add www to domain name through apache or htaccess

We given the detailed information about how to add www to domain name through apache or htaccess. Using apache rule we can achieve this.

add www to domain name through apache or htaccess
add www to domain name through apache or htaccess

Just use following code in apache configuration file or .htaccess file.

If you are using the shared hosting then please go with only .htaccess file.

Just copy paste following code in .htaccess file.

<IfModule mod_rewrite.c>

Options +FollowSymlinks

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.wordpressapi\.com$ [NC]

RewriteRule ^(.*)$ http://www.purabtech.in/files/$1 [L,R=301]

</IfModule>

Run Php code in html files

In this tutorial we will show you to Run Php code in html files. PHP is most popular server-side script in the world now. HTML is great for SEO purpose. executing PHP script is possible in HTML file.

What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

Just use following code in your .htaccess file or Apache configuration file.

AddType application/x-httpd-php .html

Or for .htm

AddType application/x-httpd-php .htm

If you only plan on including the PHP on one page, it is better to setup this way:

AddType application/x-httpd-php .html
I found following article useful.
http://php.about.com/od/advancedphp/p/html_php.htm

How to start Activemq with XML configuration file

how to start the Activemq with XML configuration file. in this article we given you step by step guide of activemq with XML configuration which will simple

How to start Activemq with XML configuration file

You can download Aapache activeMQ from following URL;
http://activemq.apache.org/activemq-530-release.html

Choose the your OS(Linux/Windows). After downloading apache-activemq-5.3.0-bin.zip.
Extract the ActiveMQ. Open command prompt and go to activeMQ/bin directory and run the “activemq” command.

ActiveMQ will start without configuration.
If you are running ActiveMQ on local machine than you can open the ActiveMQ’s Admin from following URL;
http://0.0.0.0:8161/admin/ (8161 is default port)

If you want to run ActiveMQ with XML file. Use following command
#bin/activemq xbean:file:../config.xml

server-status How to start Activemq with XML configuration file
How to start Activemq with XML configuration file

For more information Please visit the http://activemq.apache.org/

How to install and setup varnish on fedora9

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites. In contrast to other HTTP accelerators, many of which began life as client-side proxies or origin servers, Varnish was designed from the ground up as an HTTP accelerator.

Use following command:
[root@localhost siwan]# su
[root@localhost siwan]# yum install varnish
ncurses are needed for textual “graphical” configuration.
[root@localhost siwan]# yum install ncurses-devel

Edit the setting of varnish
[root@localhost siwan]# vim /etc/varnish/default.vcl

Start the varnish.
[root@localhost varnish]# /etc/init.d/varnish start

on startup set varnish on
[root@localhost varnish]# /sbin/chkconfig varnish on

How to use hosts file on Mac, Windows and Linux

The hosts file is a computer file used by an operating system to map hostnames to IP addresses.
On many operating systems, the host file content is used preferentially over other methods,
such as the Domain Name System (DNS). Unlike DNS, the hosts file is under the control of the local computer’s administrator

Locate the file “Hosts” on your computer:
Windows
Windows 95/98/Me c:\windows\hosts
Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts
Windows XP Home c:\windows\system32\drivers\etc\hosts

Linux
/etc/hosts or /etc/host.conf or /etc/nsswitch.conf

Symbian
C:\system\data\hosts

Mac OS
/private/etc/hosts or /etc/hosts

In that file you can edit entry like this

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost localhost yourlocaldomain.com , example.com
::1 localhost6.localdomain6 localhost6
192.168.2.200 intranet

directory.example.com 71.155.186.91

How to setup mongrel cluster setup on fedora

First install the following gems:
#su
#gem install mongrel
#gem install mongrel_cluster
#cd project_name
#mongrel_rails cluster::configure -e production -p 3000 -N 3 -c /home/siwan/project_name -a 127.0.0.1 —-prefix /project_name
# mongrel_rails cluster::start

You are able to start your applicaton at http://127.0.0.1:3000, http://127.0.0.1:3001 and http://127.0.0.1:3002

for all the cluster
# mongrel_rails cluster::stop

Advanced prepairation for production realeaze
$ mkdir /etc/mongrel_cluster

#vim /etc/mongrel_cluster/project_name.yml
copy and paste following text;
user: project_name
cwd: //home/siwan/project_name
log_file: /home/siwan/project_name/mongrel.log
port: “3000”
environment: production
group: dev
address: localhost
pid_file: /home/siwan/project_name/tmp/pids/mongrel.pid
servers: 3

or you can run the following command

or copy and paste the content from config/mongrel_cluster.yml file to /etc/mongrel_cluster/project_name.yml

# ln -s /home/siwan/project_name/config/mongrel_cluster.yml /etc/mongrel_cluster/project_name.yml

Then open your httpd.conf file for apache configration:

<Proxy balancer://project_name>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>

<VirtualHost *:80>
ProxyPreserveHost On
# Avoid open you server to proxying
ProxyRequests Off
# Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/(images|stylesheet|javascript|html)/?(.*) /home/siwan/project_name/public/$0 [L]
ServerAdmin siwan@yahoo.co.in
DocumentRoot /home/project_name/
ServerName example.com
RewriteRule  ^/(.*)$  balancer://project_name%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

Restart the apache server
#/etc/init.d/httpd restart

Command for restart the mongrel servers from any where
# mongrel_rails cluster::restart -C /etc/mongrel_cluster/project_name.yml

Solved: Access denied with code 400 (phase 2).

When I restarted my apache server. I am using the fedora 9 here.

I did not get my default page opened in browser.
When I opened the apache error log file. I saw following error.

ModSecurity: Access denied with code 400 (phase 2). Pattern match “%0[ad]” at REQUEST_HEADERS:Cookie. [id “950910”] [msg “HTTP Response Splitting Attack. Matched signature <%0a>”] [severity “ALERT”] [hostname “localhost”] [uri “/”] [unique_id “SuWoGH8AAAEAAFF3rKEAAAAA”]

I after doing some R&D but I did not got any perfect soluction.
Then I cleared the whole browser cookies. That solves my problem.

solution – clear the browser cookies…

Solved: DirectoryIndex not allowed here

When I tried to run my one of my project on server I got following error on the Browser.:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

When I got above error I opened the error log file.

Error Log File log(#vim /var/log/httpd/error_log)
[Wed Oct 14 12:02:56 2009] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Oct 14 12:02:56 2009] [notice] mod_python: using mutex_directory /tmp
[Wed Oct 14 12:02:56 2009] [notice] Apache/2.2.9 (Unix) DAV/2 PHP/5.2.6 mod_python/3.3.1 Python/2.5.1 mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0 configured — resuming normal operations
[Wed Oct 14 12:02:59 2009] [alert] [client 127.0.0.1] /var/www/html/your_domain_name/.htaccess: DirectoryIndex not allowed here, referer: http://your_domain_name.org/
[Wed Oct 14 12:03:29 2009] [alert] [client 127.0.0.1] /var/www/html/your_domain_name/.htaccess: DirectoryIndex not allowed here, referer: http://your_domain_name.org/
[Wed Oct 14 12:11:13 2009] [notice] caught SIGTERM, shutting down
[Wed Oct 14 12:11:13 2009] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Oct 14 12:11:13 2009] [notice] Digest: generating secret for digest authentication …
[Wed Oct 14 12:11:13 2009] [notice] Digest: done

At the end of file I saw above error.

When I saw that I opened the httpd.conf file and I searched for line.

AllowOverride None

I commented this line.
#AllowOverride None

Then I added following lines to that tag
Order allow,deny
Allow from all

Then I saved the httpd.conf file and restarted the apache server.

This solved the my issue.