0

I need to transfer URL from blog.mydomain.com to mydomain.com/blog but I don't have any experiences with mod rewrite.

The blog is on Wordpress with multisite (a was add a new site).

  1. Website mydomain.com is in dir .\mysite\
  2. Blog is in dir .\wordpress\
  3. I created subdomain blog.mydomain.com and use dir .\wordpress\
  4. I put .htaccess file into dir .\mysite\
  5. In Wordpress I created a new site for URL mysite.com\blog and used Domain Mapping plugin

I need to use blog from url mydomain.com\blog\wordpress_urls

# Redirect and keeep old url mydomain.com/blog/ => blog.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com/blog
RewriteRule ^(.*) http://blog.mydomain.com/$1 [P]

This code work but it was changing ulr. I don't use HTTPS but in future I will.

Adrian
  • 1
  • 2
  • How to create htacces file with rewrite rule for redirect from mydomain.com/blog/ to blog.mydomain.com with keeping old url (mydomain.com/blog/) – Adrian May 18 '18 at 06:00

1 Answers1

0

A rewrite without redirect requires enabled mod_proxy, as well as mod_rewrite and .htaccess through Apache's httpd.conf.

In your .htaccess under the DOCUMENT_ROOT, i.e. /mysite put:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

#if not already blog.mydomain.com
RewriteCond %{HTTP_HOST} !^blog\.mydomain\.com$ [NC] 
#rewrite request is for blog/* to blog.mydomain.com
RewriteRule ^blog/?$ http://blog.mydomain.com/$1 [L,P,NC] 

Note: You may want to specify your preferred canonical URL to avoid search engine penalties for doubled content (here a custom Wordpress sample).

wp78de
  • 18,207
  • 7
  • 43
  • 71
  • It not working for me, mod_proxy is disabled :/ Server was running on IdeaWebServer (Apache fork, dedicated solution) – Adrian May 18 '18 at 11:25