I have the following redirect code in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301,NC]
</IfModule>
# END WordPress
AddHandler php-stable .php
I'm trying to redirect all traffic from olddomain to newdomain. Not that the new domain does use "www".
When clicking on an old link elsewhere on the net that would refer to a post, redirect does seem to happen but it does not add in the correct slash after the domain name.
Here is what happens, the link to my old domain is as such on a website (just posted by someone):
http://olddomain.com/some-blog-post/
When I click on that link in a browser, it actually opens up:
http://www.newdomain.comsome-blog-post/
The slash between the domain and the blog post is missing.
Also, if it helps I'm using MediaTemple as my host for the old domain and I'm modifying my .htaccess file in
domains/olddomain.com/html/.htaccess
Anyone have any idea out there? Thanks a ton, I'm stuck.
Ok I just checked on this a little more and it turns out everything is working fine with the .htaccess code I pasted above.
My web browser was caching aggressively and I just had to dump the cache (or use private browsing).
See here for more debugging tips:
Tips for debugging .htaccess rewrite rules
maybe this is better:
RewriteCond %{HTTP_HOST} ^(.*\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ http://%1newdomain.com/$1 [R=301,L]
It matches both the subdomain and request URI and merges them with the new domain. If there is no subdomain, it proceeds to match the request and will redirect without a subdomain.
Related
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]
I have a wordpress blog "old.com" hosted in shared hosting where "old.com" is the main domain...
Then decide to redirect this "old.com" to "new.com" (an addon domain hosted in same hosting)...
I use this code on .htaccess
Options +FollowSymLinks RewriteEngine on RewriteRule ^(.*)$
http://new.com/$1 [R=301,L]
Everything works just fine. I also have an addon domain, "addon1.com" and I still can access this perfectly (I added this "addon1.com" before I redirected "old.com" to "new.com)"
The problem now is, I add "addon2.com" (another addon domain), but I can't access this domain... When I try to access this "addon2.com", it will redirect me to old.com/hxxp://addon.com and shows that the page can't be found....
Can somone help me how to solve this problem? If I remove the redirect code from .htacess, my addon2.com works just fine...
Thanks
Andi
edited
i added this on my .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www.)?addon2.com
RewriteRule (.*) hxxp://new.com/$1 [R=301,L]
and it seems like it works :)
I have a Wordpress site runing on Apache and now I want to add another domain adress to this site.
In a few words here... I have two domain names domain1.com and domain2.com .
domain1.com is set and the website is working as it should but now I want to add another domain for the same site. domain2.com, must be redirect to domain1.com, the problem is that I have no idea why it doesn't work, because when I try to access domain2.com it open the following address.
http://domain1.com/wp-signup.php?new=domain2.com
Basically this is a redirect to default domain on signup page. What should I do to fix this?
Hope you understood the question, I don't know how to explain it better.
Edit:
I've added the following rules in .htaccess and restarted apache, but the problem persists. Maybe is something from Wordpress?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)domain2.com [NC]
RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
OK, looks like all this is wordpress related and apache(htaccess) have nothing to do here. The solution that works for me:
I've added this line in wp-config.php and now it works great. Now if I access domain2.com it is redirected to domain1.com, exactly what I wanted. :)
define( 'NOBLOGREDIRECT', 'http://domain1.com' );
This is what I use for my 301 redirects:
RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^(.*)$ "http\://www.domain1.net/$1" [R=301,L]
This redirects the domain whether or not people type in the www. part of the url. The backslashes (\) escape the punctuation.
Hope this helps.
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]
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..