简体   繁体   中英

301 Redirect Not Working .htaccess

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM