Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 06-08-2017 11:56:55

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Htaccess: add or remove trailing slash from URL

Looking at <base href=" and <link rel="canonical" href=" on the home page there is a trailing slash in both at the end of the base url. In order to stop a duplicate content issue, should we have a redirect in htaccess that ensures the base url always has a trailing slash at the end of it? If so, how should we handle that in htaccess so it does not interfere with K9?

On a similar theme, a 3rd party SEO tool suggests that:

"Adding or removing a trailing slash to all URLs of this site returns an error page (404). This is OK as no content is being duplicated, but visitors might try browsing to the pages of this website with or without a trailing slash. Ideally, the alternate URL should redirect to the correct page."

How should we handle that in htaccess so it does not interfere with K9?

Last edited by sdn (06-09-2017 01:36:29)


Simon

Offline

 

#2 06-09-2017 08:52:36

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

The base URL is not an issue.  Further on, though, am I to understand you want a rewrite rule to remove a trailing slash from any URLs which use one, and 301 redirect them?


Nick Hendler

Offline

 

#3 06-12-2017 03:03:02

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

I reread the 3rd party SEO tools requirement and have decided to ignore it on the grounds that it is a bit pointless.

Does K9 add the trailing slash suffix to the base URL or is it htaccess that drives this? I just want to ensure that the base url is always served the same way i.e. with the trailing slash suffix and need to know if I need to address this with an htaccess redirect.

Also, we have the following code is htaccess:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.ourdomain\.co\.uk$
RewriteRule (.*) https://www.ourdomain.co.uk/$1 [L,R=301]

It looks like this code is also forcing the site to be served securely as https but I think that might conflict with K9.

Can you clarify.

Last edited by sdn (06-12-2017 13:03:38)


Simon

Offline

 

#4 06-12-2017 08:24:39

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

K9 will do an SSL redirect for any URL which gets accessed via Non-SSL when the site is running via SSL only.  What you are doing is heading that off with an Apache rewrite before it gets to K9.  The question you've asked has two answers:

ANSWER #1: Using Apache as you are to rewrite all URLs from http to https is very efficient and definitely the way to go if you're sure K9 isn't subsequently rewriting URLs due to SEO changes you've made in K9 (URL changes specifically).  Using Apache to do the rewrites in that case would have Apache rewriting http->https and then K9 rewriting the URL on a second try to the proper SEO URL.

ANSWER #2: If you know you've changed a lot of SEO URLs in K9 as part of your upgrade, you might likely want to forgo the .htaccess rules and let K9 do all the redirects for SSL.  Doing it this way ensures just one redirect, with K9 handling http->https and whatever SEO URL changes were necessary. 

I hope that helps.


Nick Hendler

Offline

 

#5 06-12-2017 08:57:16

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

OK I think I understand your explanation.

I did some experimentation and found that changing to "RewriteRule (.*) http://www.ourdomain.co.uk/$1 [L,R=301]" causes K9 to display the non-seo url when redirecting an seo optimised url from http to https.

So

http://www.ourdomain.co.uk/seo-url-example

becomes

https://www.ourdomain.co.uk/index.php?a … ccccccc121

which is probably not so great.

<link rel="canonical" is still correctly pointing to https://www.ourdomain.co.uk/seo-url-example though.

Is that to be expected or is something else going on that we need to look into?

Last edited by sdn (06-12-2017 09:16:56)


Simon

Offline

 

#6 06-12-2017 10:41:11

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

I think your cookie settings are incorrect.  All this has changed in 9.0.2 and is less complicated.  That's coming out any time, but for you, the cookie settings are the first place I'd look.


Nick Hendler

Offline

 

#7 06-12-2017 13:17:09

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

I have amended the rewrite code slightly as I found a page with what appears to be some coherent examples. It now looks like:

RewriteCond %{HTTP_HOST} !^www.ourdomain.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.ourdomain.co.uk/$1 [L,R=301]

When you say the cookies are incorrect, do you mean the paths set when running the installer?

They are set to

.ourdomain.co.uk
/
.ourdomain.co.uk
/

as our K9 install is straight in the public_html folder.

Is that correct?

Last edited by sdn (06-15-2017 08:21:51)


Simon

Offline

 

#8 06-14-2017 08:36:11

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

Cookies settings are correct.  Are your SSL and non-SSL URLs identical other than the http/https difference?  That http->https redirect should definitely be in SEO format, not using CGI parameters.

As far as your new rewrite, it looks good, except do you mean to have two dots after the www in both rules?  That doesn't look quite right.


Nick Hendler

Offline

 

#9 06-15-2017 08:33:36

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

Just one dot is in the actual redirect rules (typo just in forum post).

Step 3 of installer entries are:

http://www.ourdomain.co.uk
https://www.ourdomain.co.uk
443

We still have a (largely disabled) copy of CCP8 in a directory off public_html so we can manually verify some set-up details on K9. Could it impact on the K9 install? Both installers have been run to set correct paths to their respective public and private folder locations.

Last edited by sdn (06-15-2017 08:35:25)


Simon

Offline

 

#10 06-15-2017 10:15:14

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

Are you sure those rewrites are truly going to an index.php URL with CGI parameters?  They shouldn't be doing that.  Especially not with correct cookie settings and no variation between SSL and Non-SSL domains.  It's very curious.  I'm not sure if we can narrow down the problem before I get 9.0.2 out the door or not, but I'm sure that version would solve it.  I don't think a V8 install somewhere else on the account would hurt anything unless you had conflicting rules for it in your .htaccess.


Nick Hendler

Offline

 

#11 06-20-2017 03:27:42

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

Can you try the example link below to see what result you get?

http://www.quasarelectronics.co.uk/Item … 3-way-blue

I get the same index.php redirect even with all other rules removed and just this in htaccess

Options FollowSymLinks
RewriteEngine on
RewriteRule ^index.php - [L,PT]
RewriteRule ^$ index.php?COREseourl=/ [L,PT]
RewriteRule ^/$ index.php?COREseourl=/ [L,PT]
RewriteRule ^sitemap\.xml utilities/sitemap.xml [L,PT]
RewriteCond %{REQUEST_URI} ^/
RewriteCond %{REQUEST_URI} !\.(xml|css|js|gif|jpg|jpeg|png|pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?COREseourl=/$1 [L,PT]

But if I add the following (even with all the other redirects in place), the SEO url is displayed as expected.

# Force all pages to be delivered as https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.quasarelectronics.co.uk/$1 [R=301,L]

So it appears that my htaccess redirects have no bearing on the issue and it is some code in K9 or the server configuration that is the cause.

Should I submit a ticket so you can check for yourself as it is not very efficient batting these forum messages back and forth with a day or more between each response.

Last edited by sdn (06-20-2017 04:12:21)


Simon

Offline

 

#12 06-20-2017 08:26:40

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

I got a redirect http->https with an sid in the URL.  Indicates a URL mismatch in your config between the SSL and non-SSL URL.  Be sure you have a 'http' URL for the non-SSL URL, and a 'https' URL for the SSL URL.  Otherwise, they should be the same.  Use the full time SSL setting in admin to ensure SSL runs all the time.  Your cookie settings look right.  Open a ticket if these items all check out right.


Nick Hendler

Offline

 

#13 06-21-2017 01:19:21

sdn
Member
From: UK
Registered: 05-29-2007
Posts: 882

Re: Htaccess: add or remove trailing slash from URL

"Suppress SID in URLs" was set to false but changing to true resolves the issue. Please can you confirm how "Suppress SID in URLs" should be set in K9.

I was told in CCP8 forum post #2 at https://forum.kryptronic.com/viewtopic.php?id=32517 to never set it to true.

Last edited by sdn (06-21-2017 01:26:57)


Simon

Offline

 

#14 06-21-2017 08:24:51

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Htaccess: add or remove trailing slash from URL

That should be set to false.  The setting is gone in 9.0.2, and sids are gone too.  Setting that to true and the issue going away indicates my post #12 is what you need to look at.


Nick Hendler

Offline

 

Board footer