Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a domain name, blogdomain.com, which I've linked to otherdomain.com/blog using this .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?blogdomain.com$
RewriteRule ^(/)?$ blog [L]

Now when I go to blogdomain.com, I'm redirected to blogdomain.com/blog. Is it possible to write a .htaccess rule so that I can avoid the subdirectory name appearing in the new address?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Try this one

RewriteRule ^(.*)$ /blog/$1 [L]

I would suggest you to create a virtual host for blogdomain.com and point the document root to /blog/ directory

share|improve this answer
    
It's giving me a 500 error. I'm no good at .htaccess syntax so I can't tell what's going wrong. In what way does a virtual host help? Less for Apache to sort through? –  lowercasename Oct 24 '12 at 6:00
    
What is your operating system/web server? –  Hex Oct 24 '12 at 6:02
    
Heh... I'm using Apache2 on a Raspberry Pi, Raspbian OS. So for all intents and purposes it's Debian, just with an ARM processor. It's a toy server, of course, but it's had no hiccups yet. –  lowercasename Oct 24 '12 at 6:04
    
Bam. Adding this line after the RewriteRule fixed it: RewriteCond %{REQUEST_URI} !^/blog Which is odd - I don't know why it was still trying to redirect into the subdirectory, I was forcing it to go from blogdomain.com. Anyway, that's sorted. Thank you! –  lowercasename Oct 24 '12 at 6:19
    
Im happy it worked for you :) –  Hex Oct 24 '12 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.