Pedram
Pedram

Reputation: 16575

Htaccess redirect 301 not working

I want to redirect 301 my old domain to new one, and also an indexed old page to new page. here is the code:

ErrorDocument 404 /404.html
Options +FollowSymLinks

RewriteEngine on
RewriteRule ^%D8%AB%D8%A8%D8%AA-%D8%B1%D8%AA%D8%A8%D9%87-%D8%A7%D9%84%DA%A9%D8%B3%D8%A7/?$ http://newdomain.com/%D8%AB%D8%A8%D8%AA-%D8%B1%D8%AA%D8%A8%D9%87-%D8%A7%D9%84%DA%A9%D8%B3%D8%A7 [R=301,L,NC]
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

but both not working... any solution?

Upvotes: 2

Views: 79

Answers (1)

anubhava
anubhava

Reputation: 784898

  1. Don't mix mod_rewrite rule with mod_alias rules
  2. Keep specific redirects before generic catch-all redirects.

You can have it as:

RewriteEngine on

RewriteRule ^\xD8\xAB\xD8\xA8\xD8\xAA-\xD8\xB1\xD8\xAA\xD8\xA8\xD9\x87-\xD8\xA7\xD9\x84\xDA\xA9\xD8\xB3\xD8\xA7/?$ /foo-bar [R=301,L]

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

Upvotes: 1

Related Questions