Redirect a subdomain to a new URL - wordpress

I have a client that had a main site in Joomla and a blog in WordPress. We just made everything one WordPress site.
What I need help with is redirecting the subdomain (e.g. blog.example.org) to the new URL (example.org/blog).
I believe this needs to get done with .htaccess and it needs to be integrated with the WordPress stuff, too.
Here's where I got so far:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^example.health-access.org
RewriteRule ^(.*)$ http://example.org/blog/$1 [L,NC,QSA]
</IfModule>
# END WordPress
But it's not working. Any thoughts and help are greatly appreciated.

You just need to change the order:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.health-access.org [NC]
RewriteRule ^(.*)$ http://example.org/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress

Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursubdomain\.yourdomain\.com$ [
RewriteRule ^(.*) http://www.newdomain.com/?param=data&uparam2=data

Related

subdomains for different wordpress directory

I have staging.namexx.my and staging2.namexx.my now.
for staging.made4u.my, it's using directoryA
And now, i want staging2.namexx.my to use directoryB to open wordpress
*staging.namexx.my is currently working, just need to let staging to use directoryA, and staging2 to use directoryB in same server.
I'm playing with the htaccess and google for some time but still cannot get it.
I need some help.
my htaccess in root
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteCond %{REQUEST_URI} !^/dicrectoryA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dicrectoryA/$1
RewriteCond %{HTTP_HOST} ^(staging.)?namexx.my$
RewriteRule ^(/)?$ dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htaccess in directoryA
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dicrectoryA/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dicrectoryA/index.php [L]
</IfModule>
# END WordPress
htacesss in directoryB
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]
</IfModule>
# END WordPress
Thank you!
To point staging2.namexx.my to directoryB via rewrite , you could use the following rule in your root/. htaccess .
RewriteEngine on
RewriteCond %{HTTP_HOST} ^staging2\.namexx\.my$ [NC]
RewriteRule ^ /directoryB%{REQUEST_URI} [L]
Just replace staging2.namexx.my with your real domain name and keep the rule block at the top of your htaccess.

Wordpress .htaccess doesn't remove www from website's URL

Looking at the code, this should be working (its working for other websites/subdomains i'm working on)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R]
</IfModule>
# END WordPress
Edit: the website is on a Redirect Loop now.
Fixed it going into Wordpress settings > General > Website URL and adding "www." to the domain :)
your redirect should be first before WordPress handles the request.
like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

htaccess not redirecting and displaying 404

Im wondering if someone could help me out.
I have setup a 301 redirect from my .com.au to my com using htaccess which wordpress generated.
The homepage works fine except now everytime I try to navigate around my website I keep getting 404 errors
My htaccess is as follows
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.website\.com\.au$
RewriteRule ^/?$ "http\:\/\/www\.website\.com\/" [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help would be greatly appreciated
Thanks!
Try your rules this way. I also made a few changes to the first redirect rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com\.au$
RewriteRule ^/?$ http://www.website.com/ [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Redirect all pages to new domain

I want to redirect all the pages of my website to a new domain with a redirect. I've managed to get it working on domain level but not on the subpages.
So olddomain.com redirects to newdomain.com but olddomain.com/contact doesn't redirect to newdomain.com. It still shows the old domain.
I've used multiple rewrites rules but none of them seem to works. Any help is much appreciated.
This is the code that I'm using right now in my .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^racentegenkanker\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.racentegenkanker\.com$
RewriteRule ^(.*)$ "http\:\/\/againstcancer\.nl\/$1" [R=301,L]
For a full website redirection, you can use this (entire) .htaccess :
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]
EDIT
For two domains running side by side, with one redirecting the other :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} racentegenkanker\.com$
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Redirect to a new domain & change url structure htaccess

I am trying to redirect a wordpress blog from an old domain to a new domain and changing the structure of the urls on the new domain.
So I want www.domainA.com to redirect to test.domainB.com/folder/
and www.domainA.com/2001/12/some-post to redirect to test.domainB.com/folder/some-post
This is what I currently have in my htaccess file. I have managed to achieve my second objective, but if you go to www.domainA.com, it does not redirect to test.domainB.com/folder/ All the other pages redirect properly aside from the homepage.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ http://test.domainB.com/folder/$3 [R=301,NC,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am sure I am missing something elemetary, but I can't seem to figure it out :(
Try this code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?\d+/\d+/(.*)$ http://test.domainB.com/folder/$1 [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^/?$ http://test.domainB.com/folder/ [NC,L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]

Resources