Archive for the ‘.htaccess’ Category

.htaccess Generation Issues in wordpress

Thursday, February 18th, 2010

Fixing .htaccess Generation Issues in wordpress

If your installation of WordPress does not generate a .htaccess file or if it does not write the new rules onto your existing .htaccess file then there are a couple reasons that could be causing this. Work step by step and continue to the next step only if the previous step does not work.

  1. Change File Permissions: You must chmod the .htaccess file to 666 to edit it with the WordPress template editor, but this is not recommended, since if you do that, any user of your blog, who can edit templates will be able to edit it. You can change the permissions to 660 to make it server-writable, which again will have the same limitation.

  2. Server Blockage: Your host might have blocked the SERVER_SOFTWARE variable and this will cause WordPress’ .htaccess generation to fail. If you are sure that your server is running Apache, you can force WordPress to believe that your server is running Apache by changing your wp-includes/vars.php file. Follow the steps below to implement these changes.

    • Open the wp-includes/vars.php file using the built in file editor in your WordPress Admin panel. To navigate to this panel, login to WordPress, click on “Manage”, then on “Files”, scroll to the bottom and type in wp-includes/vars.php into the text box under the “Other Files” title. Look for

      $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], ‘Apache’) ? 1 : 0;

      and replace it with

      // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], ‘Apache’) ? 1 : 0;

    • Add a new line under

      // $is_apache = strstr($_SERVER['SERVER_SOFTWARE'], ‘Apache’) ? 1 : 0;

      and type in

      $is_apache = 1;

    Done

 

Redirect domain to .cgi file

Wednesday, February 17th, 2010

If you want to redirect your domain

http://domain.co.uk

to

http://domain.co.uk/cgi-bin/test/subdirectory/test.cgi file

then add the following rewrite rule in .htaccess file

====================

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.co\.uk$ [NC]
RewriteRule ^/?$ "http\:\/\/www\.domain\.co\.uk\/cgi-bin\/test\/subdirectory\/test\.cgi$1" [R=301,L]

====================

Or

====================

http://domain.com

to

http://domain.com/cgi-bin/subdirectory/test.cgi

then add the following rewrite rule in .htaccess file

====================

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ "http\:\/\/domain\.com\/cgi-bin\/subdirectory\/test\.cgi" [R=301,L]

====================

Done

CodeIgniter redirection problem

Tuesday, February 9th, 2010
If CodeIgniter is installed on the linux server and the .htaccess file is correct but your domain is not working properly then you need to set the  “uri_protocol" in the "system/application/config/config.php” file is as follows.
$config['uri_protocol']    = "REQUEST_URI";

Redirect one page to another page by using .htaccess

Wednesday, December 23rd, 2009

Add the following rule in .htaccess file

1) If you want to redirect one page to another page, add the following code to the file, on a single line.

redirect 301 /old-file-name.htm   http://www.domain.com/new-file-name.htm

Create your own Apache Rewrite Log file

Friday, December 11th, 2009

How to Create your own Apache Rewrite Log file ?

If your account is hosted on suexec server then you need to add this code in http.conf file otherwise you can enable it by using .htaccess file.

By using  http.conf file

You need to
=============================
# Roll your own Rewrite log
# Log details via scale of 1 to 9
# 1 = few details, 5 = enough details, 9 = too much detail

RewriteEngine On
RewriteLog “/home/username/public_html/rewrite.log”
RewriteLogLevel 5
=============================

By using  .htaccess file

============================
# Roll your own Rewrite log
# Log details via scale of 1 to 9
# 1 = few details, 5 = enough details, 9 = too much detail
RewriteEngine On
RewriteLog “/home/username/public_html/rewrite.log”
RewriteLogLevel 5
=============================

Note : Replace the absolute path for rewrite.log file.

How to make root domain .htaccess not affect to addon domain

Friday, December 11th, 2009

Some time the root domain .htaccess file rule affect to addon domains. So you can not access your addon domain properly. If you want to disable this rule for the addon domain then you need to add the following rule in the root domain .htaccess file.

RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
Rewriterule .* - [L]

for example addon domain is bestdesigns.co.in then rule is

RewriteCond %{HTTP_HOST} ^(www\.)?bestdesigns\.co.in
Rewriterule .* - [L]

Note : Where addon_domain should be replaced by the actual domain name, and I’m assuming that both addon_domain.com and www.addon_domain.com exist and resolve to your server.

Client denied by server configuration

Monday, December 7th, 2009

Client denied by server configuration :

Error : tail -f /usr/local/apache/logs/error_log | grep username

[Sun Dec 07 14:04:38 2008] [error] [client 203.193.165.98] client denied by server configuration: /home/username/public_html/catalog/admin/index.php

Solution:

If you get above error then you need to check .htaccess file under respective directory(here catalog/admin) and there you need to comment the rule “Deny from all”
Like this:

<Files *.php>
Order Deny,Allow
#Deny from all
</Files>

done

How to enable php setting for all Directories

Wednesday, December 2nd, 2009

If you want enable some php related setting by using php.ini file and it reflect to all  other directories which is under your account. Then follow the steps..

First create php.ini file under the document root of your domain and change or add the default setting which you want or which is required for your domain.

for example :

allow_url_fopen = On
allow_url_include = On

then you need to add the following code in your .htaccess file. So you dont need to copy the php.ini file in each directories for chnages to reflect.

SetEnv PHPRC “/home/username/public_html”


Note: Please replace user name is equal to original domain username.

What is Mod-Rewrite Module

Tuesday, December 1st, 2009
What is Mod-Rewrite Module?

Mod_rewrite is merely the Apache module that contains the rewrite engine – other servers will process URL rewriting differently.Mod-Rewrite module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism.

The RewriteEngine directive enables or disables the runtime rewriting engine. We need to tell Apache where and what to rewrite. You have two options here – more commonly, you can place the code in a .htaccess file. This is nothing more than a text file which when present in a directory will be interpreted by Apache.The other alternative is only available if you have root access and that is to place the code inside your httpd.conf

How can I enable Mod-Rewrite Module?

Before we can rewrite, there is one option we must first set: FollowSymLinks. This is a security feature of the rewrite engine and you will not be able to rewrite without this option. In most cases, this will already be set in the server httpd.conf but you can safely state it again.Additionally, if you use indexes, we must enable the Indexes option.

In order to enable Mod_Rewrite for your site you should create a text file called .htacccess in the directory where you wish the rewrite rules to apply.
================================================== ==========
#The first three lines of this text file should be:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
#After that you can place your rewrite rules
================================================== ===========

RewriteRule example :=

1] When you want Register a Domain, Find Hosting and Create a Website at Domain.com to be redirected to Register a Domain, Find Hosting and Create a Website at Domain.com, add the following in your .htaccess.

Quote:
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

2] If http://example.com/foo/bar does not exist, redirect to http://other.example.com/foo/bar. (Put this in an .htaccess file in your top-level web directory.)

Quote:
# .htaccess in root of example.com
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://other.example.com/$1 [R]

3] Handle all requests for top-level .html files and files with no extensions (http://example.com/foo, http://example.com/foo.html) with a single PHP program /foo/show.php. Also, ignore trailing characters in set { : ; , . } so URLs like “http://example.com/foo.” can be copied-n-pasted from plain text sentences by inattentive users.

Quote:
# .htaccess in root of example.com
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]

4]Here are some examples for Joomla’s SEF option:

Quote:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteRule ^(content/|component/) index.php

5]Redirect GET requests for http://example.com/foo/bar to http://example.com/bar (and /foo/bar.html to /bar.html). Handle POST requests with PHP program rather than attempting to redirect a POST (which is unlikely to work well).

Quote:
# .htaccess in foo folder in example.com’s document root
RewriteEngine On
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /$1 [R,L,NS]
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]

Redirection from http to https

Wednesday, November 25th, 2009

How to Redirect from http to https URL.

If the ssl is installed on the server and you want to all the request redirected to https then you need to add the folloing code in .htaccess file.

============================

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

============================

or

============================

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://www.domain.com [L,R]

============================

done