YoHost Home
Sign Up
Linux Hosting
Linux Hosting Plans
Linux Control Panel Demo
Reseller Information
Linux FAQ
Windows Hosting
Frequently Asked Questions
Pre-Sales FAQ
Linux Hosting FAQ
Windows Hosting FAQ
Support

YoHost Linux Hosting FAQ: mod_rewrite

Where can I find some resources that explain how to use mod_rewrite?

  A list of resources is given at modrewrite.com. There is also a message board where all aspects of mod_rewrite can be discussed.

When I try to use mod-rewrite, it seems as if the server simply stops responding. Can you tell me what is going on?

  Usually this means you've accidentally written an infinite loop! Remember that in most cases, the "rewritten" URL will be cycled back through the mod_rewrite directives that you created.

Can you give me an example of how to use mod_rewrite to handle two domains in one account?

  Sure. Suppose your domains are onedomain.com, whose content is to be placed in your directory public_html/one, and anotherdomain.com, whose content is to be placed in public_html/two. (We might also suppose that you also own onedomain.net, and its content is to be the same as onedomain.com.) You could handle the situation this way:
RewriteEngine on
RewriteCond %{HTTP_HOST} onedomain
RewriteCond %{REQUEST_URI} !^/one/
RewriteRule ^(.*) one/$1 [L]
RewriteCond %{HTTP_HOST} anotherdomain
RewriteCond %{REQUEST_URI} !^/two/
RewriteRule ^(.*) two/$1 [L]
Note: The condition "RewriteCond %{REQUEST_URI} !^/one/" is very important, because it prevents the server from going into an infinite loop!

Will mod_rewrite redirection affect the operation of my PHP and Perl scripts?

  Most PHP and Perl scripts will run just fine, even after redirection. But you may have trouble in cases where the script assumes that the requested URL corresponds to the script location.

I'm not comfortable using mod_rewrite. Can you suggest other ways to handle several domains in my account?

  Yes, you can use a PHP script. Your index.php document could contain something like the following:
<?php
$Host = strtolower ( getenv('HTTP_HOST') );
if ( strstr ( $Host, 'onedomain.com' ) ) include 'index-one.php';
elseif ( strstr ( $Host, 'anotherdomain.com' ) ) include 'index-two.php';
else echo "Oops! There is no content for host $Host.";
?>

Copyright © 2002-2017 YoHost.com
terms   privacy   contact