Reputation: 61
I want to make a 301 redirection from example.org
to example.com
The issue that I face is that all the pages are in the form of example.org/page-something.html
and I want to redirect to example.com/page-something
.
I can't figure it out no matter the tries in .htaccess
.
My current code is like this
RewriteEngine On
RewriteRule ^/(.+)\.html https://example.com/$1 [R=301,L]
The first site is a static website and the second one is WordPress in case it matters.
Upvotes: 1
Views: 224
Reputation: 25535
There are several possible things wrong.
First you have to make sure that .htaccess
is available and enabled on your example.org
site. Put some nonsense into the file temporarily and verify that the server throws a 500 Internal Server error. If you find that .htaccess
isn't being used:
.htaccess
files.)AllowOverride all
which is what enables .htaccess
.Your rewrite has a potential problem in it. From within .htaccess
the path this is matched does not start with a slash. This is different than rewrite rules used in the main Apache configuration files where the path does start with a slash. To fix this you can make the starting slash optional with a ?
. Then the rule should work in either location:
RewriteEngine On
RewriteRule ^/?(.+)\.html https://example.com/$1 [R=301,L]
You could also experiment with using a mod_alias RedirectMatch rule instead:
RedirectMatch "^/?(.*)\.html" "https://example.com/$1"
Upvotes: 2