RewriteCond %{HTTP_HOST} ^(www\.)?example\.com:8082/wordpress\
The HTTP_HOST
server variable contains the value of the Host
HTTP request header - this does not include the URL-path (ie. /wordpress/
). But why have you also include a backslash (\
) at the end, instead of a (forward) slash (/
)? Is that just a typo? (Although you've also carried that through to the example below?)
RewriteRule ([a-z0-9-]+)/? http://$1.example.com [R=301,NC,L]
Not quite sure what the idea behind this is, but this directive assumes that blog
is present in the requested URL-path - but it's not in your example? And, unless you have multiple subdomain redirects, there's seemingly no need for the generalised match and substitution?
I would also question why you need the the conditions that check that the request does not map to a directory or a file. By checking that it does not map to a directory, it won't redirect /wordpress/
(assuming this is a physical directory).
To redirect www.example.com:8082/wordpress/
to blog.example.com
as in your example (a single URL redirect*1) then you would need to do something like the following instead, at the top of your root .htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com:8082
RewriteRule ^wordpress/$ http://blog.example.com/ [R=301,NC,L]
If the .htaccess
file is located inside the /wordpress
subdirectory then change the RewriteRule
pattern to read ^$
instead of ^wordpress/$
If example.com:8082
and blog.example.com
point to different areas of the filesystem then you can remove the condition (RewriteCond
directive) altogether.
No need for the <IfModule>
wrapper or RewriteBase
directives here.
*1 Although I'm surprised you don't want to mass redirect all sub-URLs as well? ie. Redirect www.example.com:8082/wordpress/<something>
to blog.mydomain.com/<something>
. Or do you?
.htaccess
file located? In the document root, or in the/wordpress
subdirectory?