PDA

View Full Version : .htaccess Question



walkingkeyboard
04-10-2007, 09:41 AM
I have a dev subdomain for two of my addon domains. Therefore, cPanel directs both dev.addon1.com and dev.addon2.com to public_html/dev. I am trying to rewrite dev.addon1.com as addon1.com/dev and the same with addon2.

public_html/dev/.htaccess

RewriteEngine On

RewriteCond %{HTTP_HOST} ^dev.addon1.com$
RewriteRule ^(.*)$ ../addon1/dev/$1 [L]

RewriteCond %{HTTP_HOST} ^dev.addon2.com$
RewriteRule ^(.*)$ ../addon2/dev/$1 [L]

I think you can see what I'm trying to do here. What's wrong?

hillsc
05-03-2007, 01:15 PM
I'm trying to do the same (for two domains, each with a wiki). So far I've only had luck using external redirects, like so:



public_html/wiki/.htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^wiki.example.com$
RewriteRule ^(.*)$ http://www.example.com/com_wiki/$1 [R=302,L]

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


I'm still experimenting (and therefore open to suggestions!)

Charlie

Basil
05-03-2007, 01:51 PM
Homestar's got it; use absolute, not relative links in htaccess files.

Pethens
05-03-2007, 01:56 PM
You can't do it with an internal redirect (there's no ".." in mod_rewrite). If you don't mind the visible redirect, follow the example of hillsc (but why not just use addon1.com/dev in the first place?)

A simpler solution is to use:
addon1dev.addon1.com
addon2dev.addon2.com

Update: I wasn't sure about something I said so I did a test which showed you *can* use ".." in mod_rewrite. The point I was trying to make is that when you access addon1.com, as far as mod_rewrite is concerned public_html/addon1 is the top of the file system and you can't go anywhere outside of that directory tree without doing an external redirect.

hofmax
05-03-2007, 02:30 PM
Homestar's got it; use absolute, not relative links in htaccess files.

As a matter of fact always use absolute links no matter what you´re doing it´s just a lot less confusing.

hillsc
05-03-2007, 03:06 PM
(but why not just use addon1.com/dev in the first place?)

A simpler solution is to use:
addon1dev.addon1.com
addon2dev.addon2.com


It's all about appearance and perception. Granted, you could use example.com/subdomain (or two different subdomains completely, as you've shown in the second example). But you may not want to force your internal directory structure on visitors. It doesn't seem so far-fetched to want to set up two wikis:

http://wiki.AllAboutCats.cat
http://wiki.DogsRule.dog

Instead of having to tell all your dog friends to go to:

http://www.mysite.me/dog_wiki/

Charlie

[update: dreamhost allows this without any problem. When you setup an addon or subdomain, you get to spell out the full directory name for both. Therefore, in this example, I'd have: ~/public_html/wiki.AllAboutCats.cat/index.php or ~/public_html/wiki.DogsRule.dog/index.php. A lot easier, but not a big enough reason to abandon Bluehost, which wins on all other accounts. :) ]

Pethens
05-03-2007, 03:20 PM
OK, point taken. Here's how to do it within Bluehost's limitations:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^dev.addon1.com$
RewriteCond $1 !^addon1
RewriteRule ^(.*)$ addon1/$1 [L]

RewriteCond %{HTTP_HOST} ^dev.addon2.com$
RewriteCond $1 !^addon2
RewriteRule ^(.*)$ addon2/$1 [L]

The directory structure to correspond to this rule is:
public_html/dev/addon1
public_html/dev/addon2

The htaccess containing these rules goes in public_html/dev

It's untested but looks like it should work.

hillsc
05-03-2007, 05:26 PM
It's untested but looks like it should work.


And now it's tested! I just gave it a shot and it works as advertised.

I only ran into one oddity. I created subdirectories so that I could also do things like: dev.addon1.com/foo/

Which would serve this particular file (for example): ~/public_html/dev/addon1/foo/index.html

However, when I entered dev.addon1.com/foo (no trailing slash) it worked, but my URL changed to

http://dev.addon1.com/addon1/foo/ :confused:

But other than that, it works very well and would probably take care of the OP's issue. Thank you, Pethens. If anyone wants to see it in action, I picked two of my domains lockshire.net and phizzy.com and created a split subdomain for each. Check them out:

http://split.lockshire.net
http://split.phizzy.com

The second one has a couple subdirectories for playing around.

Here's my modified .htaccess




RewriteCond %{HTTP_HOST} ^split.lockshire.net$
RewriteCond $1 !^lockshire
RewriteRule ^(.*)$ lockshire.net/$1 [L]

RewriteCond %{HTTP_HOST} ^split.phizzy.com$
RewriteCond $1 !^phizzy
RewriteRule ^(.*)$ phizzy.com/$1 [L]



Charlie

blulegend
05-03-2007, 09:47 PM
Would customer service be able to point your other subdomain to a different directory so you don't need to use redirects?

charlesgan
05-04-2007, 06:48 AM
Would customer service be able to point your other subdomain to a different directory so you don't need to use redirects?

subdomain redirection always very customise.
and most adviced to DIY on the .htaccess

cause IMO.. customization not cover by BH support :D