homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewrite problem

10+ Year Member

Msg#: 880 posted 10:28 pm on Jan 16, 2004 (gmt 0)

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]



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

Msg#: 880 posted 2:52 am on Jan 17, 2004 (gmt 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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved