I’ve WordPress site with WPML installed. I’ve done 2 things recently:
- Move HTTP only to HTTPS only
- Move http://domain.pl to https://domain.xyz (English)
- Move http://domain.pl/pl to https://domain.pl (Polish)
This is done to improve SEO. However while I got that working without much problem using:
# BEGIN HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
#RewriteCond %{HTTPS} !^on$
#RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
In apache.conf file ServerName domain.xyz, ServerAlias domain.pl www.domain.pl
and so on. I’m having problems with most of my old blog posts that are around the internet in different forms. For example:
- This little entry http://domain.pl/email-address-policy/ redirects properly to https://domain.xyz/email-address-policy/
- This little entry http://domain.pl/powershell-write-host doesn’t. It simply goes to https://domain.pl/powershell-write-host which is 404 and that’s it.
It seems that last / is making huge difference.
I’ve planned to add all redirects in even direct form 1 to 1 to new domain but since it’s partially working, partially not I’m kind of lost… and I am not sure how I could translate them correctly.
EDIT:
I’ve tried multiple options, even one that supposedly rewrites all links to end with / and it still fails.
# BEGIN HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteCond %{SERVER_PORT} ^80$
#RewriteCond %{HTTPS} !^on$
#RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
#RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !^on$
#RewriteRule (.*) https://evotec.xyz/$1 [R=301,L]
#RewriteRule (.*) https://%{SERVER_NAME%}/$1 [R=301,L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} !(.*)/$
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} !.(gif|jpg|png|jpeg|css|js)$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [L,R=301]
</IfModule>
# END HTTPS
Another update:
- https://domain.xyz/url-is-here – works correctly
- https://domain.xyz/url-is-here/ – works correctly
- https://domain.pl/url-is-here – doesn’t work, isn’t convered to https://domain.xyz/url-is-here/
- https://domain.pl/url-is-here/ – convers correctly to https://domain.xyz/url-is-here/
So it’s not entirely not working for all slash vs non-slash. It’s more about translation of some sort that doesn’t happen if it points to old domain.
I’ve tried using Redirect Checker to see how it works (on proper example) but I can’t make any meaning from it.
http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1 301
Moved Permanently
https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/
301 Moved Permanently
https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/
200 OK
http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/ 301
Moved Permanently
https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/
200 OK
https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1
404 Not Found
The more options I try the weirder it gets. While the RedirectChecker seems to be showing one thing … browser is behaving a bit different and doesn’t work for the first entry anyways causing 404 straight away
Edit:
If I leave only “WordPress” data following is true:
- http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1
gets 404 http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1 exactly as is - http://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1/ gets https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/
- https://evotec.pl/hub/scripts/office365-addbulkemailaddressses-ps1 gets 404 exactly as is
It only works properly if i use the correct/new domain then all works properly:
- https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1
- https://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1
- http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1
- http://evotec.xyz/hub/scripts/office365-addbulkemailaddressses-ps1/
I guess if I can’t redirect it, i will leave it as it is and just give up.
2
Answers
I've actually solved it by using SEO Redirection Premium plugin for Wordpress.
It's able to redirect broken links without /. In this case I've done it manually but I'm working on a way to do it in more global way with Regex. Just need to find proper one.
Create a
.htaccess
file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.The
.htaccess
file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)Please REPLACE
www.newdomain.com
in the above code with your actual domain name.In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website(For SEO).
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
And Then for http to https :
And additionally you also can add the below code in wp-config.php
Note*: This may not work for you not tried, but you should try once and let me know.