Archive for the ‘htaccess’ Category

domain pointing to a folder

Tuesday, June 2nd, 2009 by dreamluverz

This approach has you code the first part of the domain or subdomain name and the associated subdirectory in your .htaccess file.   For example:





RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/
subdirectory/
RewriteCond %{HTTP_HOST} ^(www\.)?
name\.
RewriteRule ^(.*)$
subdirectory/$1 [L]

Note the second line has name, NOT name.com.   And note that there are some restrictions when using this method.

  • Domains and subdomains are treated exactly the same.  The pointing is based on the first argument of the url.  In this example name.com (as a pointed domain name) or name.domain.com (as a pointed subdomain) ends up at htdocs/subdirectory.   This is particularly useful in certain situations, for example if you want the subdomains of more than one domain to point to the same place, or if you have both a .com and a .net domain name you want pointed to the same place.
  • You must create a subdirectory under htdocs for every domain and subdomain you wish to be pointed.  The subdirectory name is then coded into the htaccess file.
  • The first argument in the url must be unique.  You cannot have two domains or subdomains with the same name.  sub.domain1.com and sub.domain2.com will both go to the same subdirectory.
  • It defaults to allow www. as a prefix on any domain or subdomain.
  • The root directory with this htaccess file is the “drop through” for any domain or subdomain not found.  You may want to put an error not found page as the default page.  Or, you could choose to have your main website be the “drop through” and just leave that one in the root.

There is also a simplified variation of this method that can be used in less complex situations where you are simply pointing a domain name and want ALL subdomains of that one domain to be pointed to a specific directory.   In this example name.com and any subdomain (including www) of that domain would be pointed to htdocs/subdirectory:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/
subdirectory/
RewriteCond %{HTTP_HOST}
name.com$
RewriteRule ^(.*)$
subdirectory/$1 [L]

In both examples, the htacess code works this way.   The first two lines set up the Apache server rewrite process.   Then you have two RewriteCond statements and a RewriteRule for EACH domain or subdomain you wish to point.

source: http://tips-scripts.com/pointing

url rewriting guide

Friday, May 22nd, 2009 by dreamluverz

Introduction to mod_rewrite

The Apache module mod_rewrite is a killer one, i.e. it is a really sophisticated module which provides a powerful way to do URL manipulations. With it you can do nearly all types of URL manipulations you ever dreamed about. The price you have to pay is to accept complexity, because mod_rewrite’s major drawback is that it is not easy to understand and use for the beginner. And even Apache experts sometimes discover new aspects where mod_rewrite can help.

In other words: With mod_rewrite you either shoot yourself in the foot the first time and never use it again or love it for the rest of your life because of its power. This paper tries to give you a few initial success events to avoid the first case by presenting already invented solutions to you.

Practical Solutions





Here come a lot of practical solutions I’ve either invented myself or collected from other peoples solutions in the past. Feel free to learn the black magic of URL rewriting from these examples. ATTENTION: Depending on your server-configuration it can be necessary to slightly change the examples for your situation, e.g. adding the [PT] flag when additionally using mod_alias and mod_userdir, etc. Or rewriting a ruleset to fit in .htaccess context instead of per-server context. Always try to understand what a particular ruleset really does before you use it in order to avoid problems.

Canonical Hostnames

Description:
The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe.
Solution:
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R]

Move Homedirs to Different Webserver

Description:
A lot of webmaster aksed for a solution to the following situation: They wanted to redirect just all homedirs on a webserver to another webserver. They usually need such things when establishing a newer webserver which will replace the old one over time.
Solution:
The solution is trivial with mod_rewrite. On the old webserver we just redirect all /~user/anypath URLs to http://newserver/~user/anypath.

RewriteEngine on
RewriteRule   ^/~(.+)  http://newserver/~$1  [R,L]

source: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

htaccess not working

Friday, October 24th, 2008 by dreamluverz

On your httpd.conf

Set this: AllowOverride All same for the other one and uncomment this line

LoadModule rewrite_module modules/mod_rewrite.so

<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>

<Directory “C:/htdocs”>

AllowOverride All
</Directory>

mod_rewrite cheat sheet

Tuesday, September 23rd, 2008 by dreamluverz

www redirect

Thursday, May 22nd, 2008 by dreamluverz

If you want to redirect your domain from http://domain.com to www.domain.com you must put this rule at the very top and before all other rules you have on your htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^(.*) http://www.mydomain.com/$1 [L,R=301]

mod_rewrite domain

Wednesday, May 21st, 2008 by dreamluverz

RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

Introduction to mod_rewrite