0

I'm trying to redirect www.domain.com to sub.domain.com except when url is www.domain.com/something and in that case keep it that way. I couldn't find any solution on the google and anytime I try to implement this in my own, I get www.www.domain.com. Thanks in advance!

Options +SymLinksIfOwnerMatch
Options -Indexes 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
0

1 Answer 1

0

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/something/?$
RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L]
2
  • That didn't seem to work. When I type domain.com it stays as it is, same about www.domain.com
    – talhof9
    Apr 1, 2013 at 11:44
  • I posted this after testing. Are you sure you have .htacess and mod_rewrite enabled? If yes then post your complete .htaccess in your question.
    – anubhava
    Apr 1, 2013 at 11:59

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