permalink and force forward slash in url
11 posts by 4 authors in: Forums > CMS Builder
Last Post: August 29, 2018 (RSS)
By moh3 - August 23, 2018
Dear Cms builder team, i'm trying to have my urls have a forward slash ( http://localhost/cms/blog/ ) in order to avoid SEO duplicate issues
i'm using the permalink plugin to create urls but i can't find out how to set this option noting i tried adding a rewrite rule to the .hta access but
it didn't have any effect
here is the rule:
Right below the RewriteEngine On
line, add:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]
to enforce a no-trailing-slash policy.
To enforce a trailing-slash policy:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R] # <- for test, for prod use [L,R=301]
By daniel - August 23, 2018
Hello,
Could you please provide your whole .htaccess content including the change you tried?
Thanks,
Technical Lead
interactivetools.com
By moh3 - August 24, 2018
hello, below is my code without the forward slash part:
# START: CMS Permalink Code
<IfModule mod_rewrite.c>
RewriteEngine On
### Manually detect URL Scheme (http or https). Cloud Servers & Load Balancers don't always give correct value
### ... of: HTTPS, REQUEST_SCHEME, SERVER_PORT, but ENV:HTTPS is sometimes manually set for us so we check both.
RewriteCond %{HTTPS} on [NC,OR]
RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule .* - [E=URL_SCHEME:https,S=1]
RewriteRule .* - [E=URL_SCHEME:http]
### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule .* %{ENV:URL_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule .* %{ENV:URL_SCHEME}://%1%{REQUEST_URI} [R=301,NE,L]
### Force HTTPS secure connections - Optional security (uncomment to use)
#RewriteCond %{ENV:URL_SCHEME} http$ [NC]
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
### Pass URL to permalinks dispatcher (do this last after any www or https redirects)
RewriteRule ^permalinks_dispatcher\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/permalinks_dispatcher.php [L]
</IfModule>
# END: CMS Permalink Code
By daniel - August 28, 2018 - edited: August 28, 2018
Hello,
In most cases, altering your htaccess to the following should work to enforce trailing slashes:
# START: CMS Permalink Code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R] # <- for test, for prod use [L,R=301]
### Manually detect URL Scheme (http or https). Cloud Servers & Load Balancers don't always give correct value
### ... of: HTTPS, REQUEST_SCHEME, SERVER_PORT, but ENV:HTTPS is sometimes manually set for us so we check both.
RewriteCond %{HTTPS} on [NC,OR]
RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule .* - [E=URL_SCHEME:https,S=1]
RewriteRule .* - [E=URL_SCHEME:http]
### Force www. prefix - (RECOMMENDED/OPTIONAL) SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule .* %{ENV:URL_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
### Remove www prefix - Optional SEO to prevent duplicate urls (uncomment to use)
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule .* %{ENV:URL_SCHEME}://%1%{REQUEST_URI} [R=301,NE,L]
### Force HTTPS secure connections - Optional security (uncomment to use)
#RewriteCond %{ENV:URL_SCHEME} http$ [NC]
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
### Pass URL to permalinks dispatcher (do this last after any www or https redirects)
RewriteRule ^permalinks_dispatcher\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/permalinks_dispatcher.php [L]
</IfModule>
# END: CMS Permalink Code
However, if this does not work, the next thing to look at is if trailing slashes show up when entering a permalink that doesn't exist. (e.g. "www.your-domain.com/12345") If yes, then that means your htaccess is correct, but there's some other configuration altering the permalinks. One thing to look into is the "MultiViews" option in the Apache configuration.
Let me know if you have any further questions.
Thanks,
Technical Lead
interactivetools.com
By Dave - August 28, 2018
Moh3,
Just curious, where are the links coming from that don't have a slash on the end? Shouldn't all permalink generated links have a slash?
interactivetools.com
By moh3 - August 28, 2018
dear dave, the concept i'm after is to have http://localhost/cms/blog to become http://localhost/cms/blog/ at the current time they both are working with and without the slash this will end in SEO duplicates as they would be considered different pages , i know the canonical tags but why not avoid all that and have the server inforce either with or without but not both
By moh3 - August 28, 2018
your suggested code didn't work as it redirects out of the working directory (/cms/) any thought how can i have it to redirect within that folder ?
By Dave - August 28, 2018
Hi moh3,
There's some more details on how google views this issue here: https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html
Are you running the latest CMSB and Permalinks plugin? I'm going to see if we can update the plugin within the next week or so to automatically redirect to urls with trailing slashes.
interactivetools.com
By Toledoh - August 28, 2018
That’ll be great Dave. I’m asked often about that also.
Tim (toledoh.com.au)
By moh3 - August 28, 2018 - edited: August 29, 2018
Dear Dave, i do have both latest CMS Builder and Perma links Plugin , actually had it CMS Builder since 2012 :) i'm a believer
that would be wonderful, i actually found a solution i'm only doing some tests on my local host but i have an issue in setting the env variable that detects (http/https) in the .hta access file
### Manually detect URL Scheme (http or https). Cloud Servers & Load Balancers don't always give correct value
### ... of: HTTPS, REQUEST_SCHEME, SERVER_PORT, but ENV:HTTPS is sometimes manually set for us so we check both.
RewriteCond %{HTTPS} on [NC,OR]
RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule .* - [E=URL_SCHEME:https,S=1]
RewriteRule .* - [E=URL_SCHEME:http]
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/cms/$1$2/ [L,R=301]
How do i assign the http / https to be automatically detect in rule above?
A side note is the documentation must be extended to have more information on the avaiable functions,hooks and other API that we can use
this software is one of the best and you build virtually anything but is lacking that information
thanks