Need help with .htaccess rewrite

This is a discussion on Need help with .htaccess rewrite within the Apache Web Server forums, part of the Web Server and Related Forums category; Hiyee I've been googling for a whole day now and can't find a decent example/guide/howto on ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-10-2006
rverrips
 
Posts: n/a
Default Need help with .htaccess rewrite

Hiyee

I've been googling for a whole day now and can't find a decent
example/guide/howto on the various variables, and functions available
for Rewriting and Redirecting using only a .htaccess file.

I have one host with multiple domain names (it's hosted, so I need to
make changes in the .htaccess file)

The host is domain1.com, and what I'm hoping to achieve is just to
redirect hits to the root of domain2.com to domain2.com/subdir and
still present in the browser as domain2/subdir (At present, hits to
the root of domain2.com present as domain1.com, but domain2.com/subdir
works fine)

All the rewrite rules I've tried either rewrite my entire domain1.com
to domain2.com as well, or don't present in the browser as
domain2.com/subdir, but rather only as domain2.com

And ideas where I can find some decent doc's on writing .htaccess files
as I'm aware I need to do some exclusions to get this working

Thanks

Roy

  #2 (permalink)  
Old 05-10-2006
Robert Ionescu
 
Posts: n/a
Default Re: Need help with .htaccess rewrite

rverrips wrote:
> The host is domain1.com, and what I'm hoping to achieve is just to
> redirect hits to the root of domain2.com to domain2.com/subdir and
> still present in the browser as domain2/subdir


So you're looking for an external (visible) redirection?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule ^$ /subdir/ [R=301,L]


to keep this internal, you could use

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteRule ^(.*) /subdir/$1 [L]

--
Robert
  #3 (permalink)  
Old 05-10-2006
rverrips
 
Posts: n/a
Default Re: Need help with .htaccess rewrite

Thanks for the quick reply Robert

I'm not sure what you mean with internal and external - Both the hosts
are on the same apache server ... (internal, no?)

Could you explain why the www is in brackets, and what the ^ and ?
represent?

Thanks

Roy

  #4 (permalink)  
Old 05-10-2006
Paul Lautman
 
Posts: n/a
Default Re: Need help with .htaccess rewrite

rverrips wrote:
> Thanks for the quick reply Robert
>
> I'm not sure what you mean with internal and external - Both the hosts
> are on the same apache server ... (internal, no?)
>
> Could you explain why the www is in brackets, and what the ^ and ?
> represent?
>
> Thanks
>
> Roy


^(www\.)?domain2\.com

This is a regular expression. The ^ means that this is the beginning of the
url string. The ? means match this if it occurs zero or one times. The
"www." is inside brackets to indicate that the ? is referring to the whole
string "www." Without the brackets, it would refer only to the ".".
So this expression says match www.domain2.com or domain2.com but do not
match something.domain2.com or something.www.domain2.com.

HTH

Regards
Paul


  #5 (permalink)  
Old 05-11-2006
rverrips
 
Posts: n/a
Default Re: Need help with .htaccess rewrite

Thanks Paul, The explaination of ? and ^ helped me a lot and I've been
able to do what I was hoping for ...

Kudos

Roy

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:31 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0