cancel
Showing results for 
Search instead for 
Did you mean: 

htaccess redirect to subdir

Vega
Rising Star
Posts: 114
Thanks: 13
Registered: ‎22-06-2009

htaccess redirect to subdir

I have the following code in my .htaccess file located in my /public folder
RewriteEngine on
RewriteCond %{HTTP:Host} ^(?:www.solareclipse2015.org.uk)?$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteRule ^(.*) /wordpress/$1 [NC,L,NS]
Its working fine when www.solareclipse2015.org.uk is entered in a browser, however http://solareclipse2015.org.uk (without the w's) is not redirecting. Does anybody know how I can fix this?
Regards
2 REPLIES 2
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: htaccess redirect to subdir

That .htaccess code checks for either the complete www.domain or an empty host string
Adapting this one, based on Gabe's post here, should meet your needs. This makes any subdomain optional.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+\.)?yourdomain\.co\.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/yoursite/
RewriteRule (.*) /yoursite/$1
David
Vega
Rising Star
Posts: 114
Thanks: 13
Registered: ‎22-06-2009

Re: htaccess redirect to subdir

That works! Grea thanks  Wink