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 http://website.com/index.php?ctrl=location&action=view in the url, it does a 301 redirection to http://website.com/test.html.

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 testdomain1.com pages to a new server
RewriteRule "^/2018/04/01/Article-1/$" "http://testdomain2.com/Article-1" [R=301,L]
RewriteRule "^/2018/04/02/Article-2/$" "http://testdomain2.com/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 ^(.*)$ http://testdomain2.com/ [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 http://www.testdomain1.com/2018/04/02/Article-2/ -o example.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.testdomain2.com/$%224">here</a>.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at www.testdomain1.com Port 80</address>
</body></html>

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.

oldsite.fr/page1 --> www.newsite.com/my-new-url-name [OK]

www.oldsite.fr/page1 --> www.newsite.com/my-new-url-name [NOT-OK]

i got www.newsite.com/page1 instead of www.newsite.com/my-new-url-name

my .htaccess is as follow :

Redirect 301 / https://www.new-site.com/
Redirect 301 /page1 https://www.new-site.com/new-name-for-url
Redirect 301 /page2 https://www.new-site.com/another-new-name

Thanks in advance

htaccess – redirect problems with domain root and subdirectories

I have a domain www.old_domain.de and like to redirect only the startpage to www.new_domain02.de/subdirectory_start.

All the other subdirectories of www.old_domain.de/ (www.old_domain.de/subdirectory01, www.old_domain.de/subdirectory02, etc) should be redirected to www.new_domain.de/subdirectory01, www.new_domain.de/subdirectory02 ...

I like to do this with a htaccess.

My tests didn't work:

RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://www.new_domain.de/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.de [NC]
RewriteRule ^(.*)$ https://www.new-domain.de/subdirectory_start [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 https://whatmovieshouldiwatchtoday.com/error404.php

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 Whatmovieshouldiwatchtoday.com" and after few seconds, it shows

This page isn’t working

whatmovieshouldiwatchtoday.com redirected you too many times.

Try clearing your cookies.

ERR_TOO_MANY_REDIRECTS

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, https://www.example.com/index.php redirect to https://www.example.com/ 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$ https://www.aviatrix.com/$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 : https://www.example.com/news/events/event18

to a unique folder : https://www.example.com/focus

Using htaccess file in Wordpress, i tried :

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

Result is:

https://www.example.com/newfolder/oldpage1

Another method:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^oldfolder/(.*)$ https://www.example.com/newfolder [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:

https://www.domain.de/aaa/bbb/

and i wanna redirect it to:

https://www.domain.de/ccc.html

and thats what i already tried:

Redirect 301 /aaa/bbb/ https://www.domain.de/ccc.html

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

and

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

</IfModule>

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 "http://abcfoto.ro/ce-este-profunzimea-de-camp-depth-field-15/" 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} ^abcfoto.ro [NC,OR]
RewriteCond %{HTTP_HOST} ^www.abcfoto.ro [NC]
RewriteRule ^(.*)$ https://abcfoto.ro/$1 [L,R=301,NC]

and

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

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