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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |