Category Archives: http-status-code-301

How to use htaccess to do a permanent redirect with status code 301?

I have the following code in my htaccess :

RewriteRule ^test.html$ index.php?ctrl=location&action=view [L]

The problem is that my page is accessible by 2 addresses :

  • ./index.php?ctrl=location&action=view
  • ./test.html

And I would like that, when I type in the url, it does a 301 redirection to

I tried the following but it does the contrary :

RewriteRule ^test.html$ index.php?ctrl=location&action=view [R=301,L]

And I tried other things but it never worked.

Apache redirects overwriting inconsistently

I have multiple rewrite rules configured for a domain, to serve specific articles by 301ing to a new domain, and two catch-all rules for rules that don't match

RewriteEngine on
# Rewrites for specific pages to a new server
RewriteRule "^/2018/04/01/Article-1/$" "" [R=301,L]
RewriteRule "^/2018/04/02/Article-2/$" "" [R=301,L]
# Catch-all for images (pass them through)
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]
# Redirect for all other matches
RewriteRule ^(.*)$ [R=301,L]

The issue I am running into is that while Article-1 matches fine and serves a 301, requests to Article 2 appear to be caught up by the last rule in the redirect. I'm not entirely sure why this is occurring, but any advice would be helpful, before I add the remaining 6400 entries to the redirect file.

To help with debugging, here's the markup for a curl call to the article 2 test path:

curl -0 -o example.html

<title>301 Moved Permanently</title>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="$%224">here</a>.</p>
<address>Apache/2.4.18 (Ubuntu) Server at Port 80</address>

htaccess 301 Redirect www and non-www

I am changing my domain name and i would like to redirect old content to the new website with some url name change. --> [OK] --> [NOT-OK]

i got instead of

my .htaccess is as follow :

Redirect 301 /
Redirect 301 /page1
Redirect 301 /page2

Thanks in advance

htaccess – redirect problems with domain root and subdirectories

I have a domain and like to redirect only the startpage to

All the other subdirectories of (,, etc) should be redirected to, ...

I like to do this with a htaccess.

My tests didn't work:

RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.de [NC]
RewriteRule ^(.*)$ [R=301,L] 

Can anyone give me insights in how I get this work? I am a new in using a htaccess.

Thank you.

HTTP to HTTPS redirect using .htaccess file not working

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

ErrorDocument 404

php_flag display_errors 1

RewriteEngine On
RewriteRule ^/?movie/([0-9A-Za-z-:-]+)/?$ /movie.php?id=$1 [NC,L] 

RewriteEngine On
RewriteRule ^/?cast/([0-9A-Za-z-:-]+)/?$ /cast.php?cast=$1 [NC,L] 

RewriteEngine On
RewriteRule ^/?keyword/([0-9A-Za-z-:-]+)/?$ /keyword.php?keyword=$1 [NC,L] 

This is my code, now this part of the code is supposed to redirect HTTP to https, but it is not working:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

When I try to open my website (even with https), Google chrome shows "Waiting For" and after few seconds, it shows

This page isn’t working redirected you too many times.

Try clearing your cookies.


index.php to root in htaccess

What does this mean? I am trying to remove index.php from the URL and point to root. For example, redirect to The below solution works absolutely fine. However, I am unclear about the HTTP/ used in RewriteCond line. What does it do? Can someone please explain?

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$$1 [R=301,L]

Redirect sub-folders to a new folder in WordPress

I have been struggling to redirect old urls to the new website pages.

Goal is to redirect many sub-sub folder pages like :

to a unique folder :

Using htaccess file in Wordpress, i tried :

RedirectMatch 301 /oldfolder1/oldpage1/(.*) /newfolder/$1

Result is:

Another method:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^oldfolder/(.*)$ [R=301,L]

Result is the same !

I have ton of old urls and I want to avoid the manual Redirect 301 for all ot them.

Thx for help.

How to 301 redirect via htacces

I'm trying to setup a 301 redirect for the following link:

and i wanna redirect it to:

and thats what i already tried:

Redirect 301 /aaa/bbb/

RewriteRule ^aaa/bbb/$ /ccc.html? [L,R=301]


<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /aaa/bbb/ /ccc.html


none of them worked for me. Any hints for me?

301 redirect works in browser, but tools checkers say it’s still a 200 response

I've been having a few problems switching a website from HTTP to HTTPS. The problem appears when I redirect via .htaccess.

If I type "" in browser the correct page is loaded, but when I do check the redirect code with the available online tools it shows as still pointing to the http page and gives a 200 code.

Some pages don't have this issue (homepage, search page) and do redirect also in browser and in the online tools with a 301 code. I've tested with pretty much every tool on the first Google page where I've searched for "redirect checker".

I've tried both solutions found online for .htaccess and both work the same way:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Any ideas would be appreciated to fix this mess. Thanks!