1

I have made a redirect rule in my .htaccess file for https://pg-flowsolutions.com that specifies that if someone enters an invalid path (for instance https://pg-flowsolutions.com/blablabla) the visitor should be redirected to the websites index.

Now this works fine in Google Chrome, but in Safari and IE I'm experiencing that an extra 's' is appended to the address bar, so the browser is attempting to open httpsS://pg-flowsolutions.com - which obviously creates an error.

So the error I am looking for help to solve is where the extra 's' that is included in the address bar when opening a invalid URL actually comes from.

Is it something in my .htaccess file that causes this, can the extra 's' be caused by some server settings in Apache, or is it perhaps something that can be corrected in Wordpress even?

I have not been able to identify what causes this behaviour, my .htaccess file is the suspected culprit but I have not been able to find any errors there.

It currently forces all HTTP visitors of the site to the HTTPS version, and also it is supposed to redirect all attempts to open an non-existing page to the index site.

As mentioned, this works for me in Chrome but not other browsers.

My .htaccess file looks like this

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
  • Do you have access to the server config? Do you have any other .htaccess file? Please include the HTTP response headers in your question. The problem is not in the .htaccess file you have posted. But the code you posted doesn't "redirect the visitor to the websites index", it internally rewrites the visitor's request to index.php - this is probably what you meant, but it is quite different and does not involve a redirect. – MrWhite Nov 17 '17 at 13:36
  • Sorry but the question as it stands is impossible to answer without speculating and makes the question unclear. If you are redirecting pages that do not exist to the homepage (of which I don't recommend, 404 improves user experience, not dampens) then you need to edit the question and include the code that controls this element since the code you have provided has nothing to do with that aspect. – Simon Hayter Nov 17 '17 at 13:40
  • Also, I've noticed your site is a WordPress site that already implements "pretty URLs", so you are already using the front-controller (in your .htaccess) to route "invalid paths"? Entering an invalid WP URL should be resulting in a WP generated 404 - but it is not, so you have other code that is intercepting this? Incidentally, if you really did want to "redirect invalid paths to the websites index" then you can't do this using .htaccess if you are using WordPress. – MrWhite Nov 17 '17 at 13:47
  • @SimonHayter did my clarification help? – lundzern Nov 17 '17 at 17:16
  • @lundzern Okay, as long as nothing else is controlling the redirect from 404 to homepage then you should be okay. I'll reopen. – Simon Hayter Nov 17 '17 at 22:39
2

You should seriously consider NOT redirecting soft 404's to the homepage! not only does it dampen the users experience provided, Google and Bing are unlikely to take a liking to it either But if you insist...

Delete the contents of your .htaccess file and import the following:

# BEGIN Removing WWW and Enforcing SSL
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
</IfModule>
# END Removing WWW and Enforcing SSL

# 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

Edit your WordPress 404.php

Then in your WordPress theme files (found in appearance) find 404.php and rename it 404-old.php, if there isn't one don't worry. In the theme folder create a 404.php and import the following:

<?php
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://pg-flowsolutions.com/');
    exit();
?>

I don't want to edit my 404.php

While I recommend editing 404.php you may prefer not too, if not you could simply the following code at the bottom of your htaccess file:

  • ErrorDocument 404 /index.php

WordPress Site Address

SOURCE

Ensure that you update WordPress to work as HTTPS, this can be done by login into the WordPress Dashboard and going to Settings > General. Then update these URLS:

WordPress Address URL Settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.