KrMa
KrMa

Reputation: 713

.htaccess redirect my site gives internal error

I am trying for the first time to make a .htaccess file. For at start I would like to make a redirect, so if a person writes:

https://example.com/robots.txt

the person will be redirected to

https://example.com

I made the file, and added the following code:

Redirect 301 https://example.com/robots.txt/ https://example.com/index.php

I also tried with:

RedirectMatch 301 ^/bonus https://example.com/robots.txt
RedirectMatch 301 ^/ https://example.com/

which both resulted in my site got internal error. So how is the correct way to do that?

Upvotes: 1

Views: 34

Answers (1)

Joe
Joe

Reputation: 4917

I'm not 100% sure why you would want to direct away from your robots.txt file as this could stop search engine crawlers from accessing the file... but you can do it using this:

Redirect 301 /robots.txt /index.php

or, try this:

Redirect 301 /robots.txt https://www.example.com/

To then to get rid of www use this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Upvotes: 1

Related Questions