Rewrite catalog to domain without changing URL - wordpress

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).
Website mydomain.com is in dir .\mysite\
Blog is in dir .\wordpress\
I created subdomain blog.mydomain.com and use dir .\wordpress\
I put .htaccess file into dir .\mysite\
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.

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).

Related

Installed Wordpress Network with www in the Site URL. How do I fix this?

I made a huge mistake. I set up a network without changing sitename to non-www, so now example.com (without www) is a non-existing page. How do I fix this? Changes in
settings
DNS
htaccess
?
I've tried htaccess redirect but wordpress sees the first request and still says www is missing.
We can't edit the Wordpress source code to redirect, as it will be broken on future updates. We can't forward all requests to the www-version of that request as that will break all subdomains.
I solved this with some edits to the root .htaccess file.
# This is probably how your file starts already
RewriteEngine On
RewriteBase /
# Then you add a condition: if the host starts with example.com
RewriteCond %{HTTP_HOST} ^example.com.*$
# And add a rule: redirect that url to the same url just with prepended with www
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Here the file continues with other stuff from WP
RewriteRule ^index\.php$ - [L]

How to redirect subdomain of wordpress site to domain root?

I have a wordpress subdomain that I need to redirect to the main domain and I would like the subdomain masked. How do I do this? I tried the wordpress redirection plugin but that didn't work.
http://2014.mydomain.com to go to http://mydomain.com
Also upon redirection I do not want my subdomain name to appear.
Thank you!
Try adding this to the htaccess file in your document root (the one for 2014.mydomain.com). Make sure to add the rules before any wordpress related rules that's already in the htaccess file:
RewriteCond %{HTTP_HOST} ^2014\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R]

Force Redirect www.domain.com\blog to domain.com\blog .htaccess?

I have a wordpress Multisite instance that for some reason defaults to domain.com (/blog with no www in front. Any request with a www in front gets forced to the home page (domain.com/blog) and not to it's intended page of say domain.com/blog/page.
What I am trying to do is force all incoming traffic to strip off www if it exists and just go to /blog/what-ever-page-youre-trying-to-go-to. I need it to go to the page that is requested, currently if you have anything on the end of the /blog URL (/blog/ANY-PAGE-HERE) it defaults to /blog.
Anyone have any idea how I would go about fixing this? In .htaccess seems to be the easiest way but I can't seem to find a viable solution after working on it for a couple of hours.
PS: it's multisite so I cannot just go into setting and change the URL and HOME to www.domain/blog
This is what I use on my sites:
<IfModule mod_rewrite.c>
RewriteEngine on
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
</IfModule>
Add this above all your wordpress stuff in the htaccess of your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.net$ [NC]
RewriteRule ^blog(.*) http://domain.net/blog$1 [L,R=301]

Using .htaccess to redirect a domain to another URL

I have a site running wordpress, it's the full site. One of the pages is like a contact-us form located at www.ourdomain.com/contact-us/
I also have a URL like contactourdomain.com and I want it to redirect to www.ourdomain.com/contact-us/
We used to do this with a redirect on network solutions, but I prefer to have it all done right on the server if possible. I've got it sort of working but when you visit the link is still says contactourdomain.com/contact-us/ as the URL, and that breaks all the other ones.
Any suggestions?
.htaccess
Options -MultiViews
RewriteEngine on
RewriteBase /
# Rewrite
RewriteRule ^(.*)$ http://www.ourdomain.com/contact-us//$1 [L]
if you add this in .htaccess is it working?:
RewriteRule ^$ contact-us/ [R=301,L]
keep me posted..

htaccess url rewriting question

I have a site made with CodeIgniter with a WordPress site at /blog.
Say I create a page in WordPress that can be viewed at /blog/my-page.
Is it possible to rewrite the URL with .htaccess to remove the blog part of the URL? So I could enter my site url /my-page to view the page?
from the top of my head..
#start the engine
RewriteEngine on
#requests to www.yourpage.com/anything/
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$ [NC]
#are sent to www.yourpage.com/blog/anything/
RewriteRule .* /blog/%1 [L]
The rule below will rewrite (internal redirect) /my-page to /blog/my-page:
RewriteEngine On
RewriteBase /
RewriteRule ^my-page$ /blog/my-page [NC,L]
RewriteRule ^another-page$ /blog/another-page [NC,L]
This needs to be placed in .htaccess in website root folder.
If you already have some rewrite rules there then this one need to be placed in appropriate place as order of rules matters.
You still may need configure WordPress a bit so it understands that this URL is for him to process (WordPress may still see the original URL). I have not worked with WordPress that much to tell if this will be required (and how to do it if it is) -- but look at Permalinks settings.

Resources