Tarek Mostafa
Tarek Mostafa

Reputation: 398

Adding 301 redirect in .htaccess isn't working

I have some code inside the .htaccess file and I would like to add to it a 301 redirect to redirect some pages to new locations, but somehow the 301 redirects aren't working

The 301 redirects I'm trying to add is:

### 301 Redirects ###
Redirect 301 /old_page.html /new_page
Redirect 301 /old_page.html /new_page
Redirect 301 /old_page.html /new_page
Redirect 301 /old_page.html /new_page

I have around 100 pages to redirect, so I copy the above code for every page.

The problem is the above code isn't working and the pages don't redirect. I think that code is conflicting with the existing code in the .htaccess file.

The existing code in the .htaccess is:

<IfModule mod_rewrite.c>
RewriteEngine On

### SSL HTTPS Redirect
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

### Exrx.net/page will display the contents of Exrx.net/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

### 301 from Exrx.net/page.html to Exrx.net/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

### -- concrete5 urls start --
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
### -- concrete5 urls end --

I'm not expert in .htaccess, could someone point me to the conflict and why the 301 redirects I'm adding aren't working?

Upvotes: 0

Views: 1271

Answers (1)

Jan R.
Jan R.

Reputation: 1

RewriteCond %{HTTP_HOST} ^(www\.domain\.com)|(domain\.com)$ [NC]
RewriteRule ^old_page\.html$ /new_page/ [R=301,L]

Redirects www.domain.com/old_page.html to www.domain.com/new_page/

Upvotes: 0

Related Questions