Ryan Grush
Ryan Grush

Reputation: 2128

301 redirect not working through .htaccess

I found this little trick http://css-tricks.com/snippets/htaccess/301-redirects/ to redirect my old Wordpress domain to my new domain with the path included. I run a test on my local copy and everything works fine. When I log in to the cpanel of the old domain and try it though it gives me some bad results.

Here is the code I used for both my local and live copy ...

# 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

Redirect 301 / http://newsite.com/

Here's what the results look like http://www.cuponsmercado.com.br/lojas/. It looks to be calling the new domain (based on the Google Chrome status at the bottom left) but it just shows the old domain with broken HTML/CSS. Any Ideas?

UPDATE: I was mistakenly editing the same domain when I thought I was editing both. Both were hosted on the same hosting account but displayed separate cPanel URLs leading to the confusion. There was a chance one .htaccess was conflicting with the other domain as well.

Upvotes: 0

Views: 137

Answers (2)

anubhava
anubhava

Reputation: 784898

Make this as first rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?cuponsmercado\.com\.br$ [NC]
RewriteRule ^ http://www.cuponsdemercado.com.br%{REQUEST_URI} [L,NE,R=302]

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143856

You need to stick with mod_rewrite because a request will get both modules applied (Redirect is mod_alias):

Above your # BEGIN WordPress section add:

RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301]

Additionally, you can use mod_alias and get rid of all the old wordpress rules if you are simply moving your site from one server to another.

Upvotes: 0

Related Questions