Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewrite problem



10:28 pm on Jan 16, 2004 (gmt 0)

Inactive Member
Account Expired


I am trying to make all request to halo.example.net refer to www.example.net/apps/halo.

Here is my .htaccess
ErrorDocument 403 /403.jsp
ErrorDocument 404 /404.jsp
ErrorDocument 500 /500.jsp

RewriteEngine on

RewriteCond %{HTTP_HOST} ^halo$
RewriteRule ^(.*)$ http://www.example.net/apps/halo/$1 [R=301,L]

RewriteBase /
RewriteRule ^([a-z_A-Z0-9]+)$ index.jsp?title=$1
RewriteRule ^photos/([a-z_A-Z0-9]+)$ /photos/index.jsp?title=$1

AddType application/x-java-jnlp-file jnlp

The lines that concern me are:
RewriteCond %{HTTP_HOST} ^halo$
RewriteRule ^(.*)$ http://www.example.net/apps/halo/$1 [R=301,L]

Everything else works properly.

With this .htaccess file when I type in http://halo.example.net in address bar I get this error:

You don't have permission to access / on this server.

If I change the rewrite rule and condition to look like this:

RewriteCond %{HTTP_HOST} ^halo$
RewriteRule ^(.*) http://www.example.net/apps/halo/$1

I get this error:

404 Not Found
/403.jsp was not found on this server.

Can someone tell me what I am doing wrong.

Thank you,

[edited by: jdMorgan at 2:42 am (utc) on Jan. 17, 2004]
[edit reason] No specific URLs, please. See TOS. [/edit]

2:52 am on Jan 17, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0


Welcome to WebmasterWorld [webmasterworld.com]!

I suggest you remove your ErrorDocument directives (comment them out with #) and the second rewrite ruleset, and get the domain-to-subdirectory rewrite working first. The script invocation via ErrorDocument will only confuse the issue for now.

You may need to move the RewiteBase directive above the first ruleset as well.

The first ruleset won't work because it will only be applied if the requested hostname is exactly "halo" - not "halo.example.com" or "halo.example.net" - only "halo". The problem is the end anchor "$". It should be removed. The start anchor "^" is needed to make sure the requested hostname starts with "halo..." and not "www...".

The second ruleset also has a problem in that RewriteRule can't "see" query strings; You'll need to use RewriteCond %{QUERY_STRING} to test or back-reference the query string.