Support

Admin Tools

#20987 Trailing slash only on home page

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by nicholas on Friday, 19 September 2014 05:34 CDT

user80278
Hello,

Is there a way to add a trailing slash at the end of my home page URL, so that looks like this
https://mydomain.com/
But without any trailing slash at the end of any pages on my website, for example
https://mydomain.com/contact

Best Regards
Mats

nicholas
Akeeba Staff
Manager
Short answer: this is not possible due to the way Joomla! and web servers work.

Long answer:

This is how the Apache web server works (and, honestly, every other web server such as NginX, IIS and so on). Let's see what each URL means.

https://mydomain.com/ means "go to mydomain.com and list the contents of the web root directory". Apache sees that and looks for the default index file. On most web servers this is index.html, index.html and index.php – not necessarily in this order. The only thing you can do is change the index files and their order. This is done by default if you are using Admin Tools' .htaccess Maker making index.php the first index file. Since there is an index.php file in your site's root, Joomla!'s entry point file, it is executed and the result is sent to your browser, rendering your site's front-end home page.

https://mydomain.com/contact means "go to mydomain.com and list the contents of the /contact directory under the web root". This directory of course doesn't exist. This is where the SEF section of your .htaccess kicks in and tells Apache "if someone asks you to show the contents of a file or directory you have not heard of hand it over to the index.php file at the site's root". Apache does that. Joomla! then decodes the "/contact" directory via a process called inverse SEF routing (also known as "SEF parsing") and figures out which internal URL (based on your menu item settings) it should show.

Now that described how Joomla! performs the inverse SEF routing. Joomla! also has an API to generate SEF URLs that's called JRouter and all developers must use it, both for built-in and third party extensions. JRouter performs the SEF routing, converting a non-SEF URL (e.g. index.php?option=com_foobar&Itemid=1234) to a SEF URL (e.g. http://www.example.com/foobar/awesomesauce). There's just one limitation in JRouter: it must ALWAYS return something. If you try to SEF-route the non-SEF home page URL (index.php) JRouter responds with a single forward slash (/). This is prefixed with your site's domain name, therefore the SEF-routed home URL becomes http://mydomain.com/ with a trailing slash.

Since this is a limitation of the Joomla! API –with a very good reason to be like that, but I digress– we can't change it. In theory we could redirect http://mydomain.com/ to http://mydomain.com but this causes two major problems:
  • The HTML output of all pages still lists the home page as http://mydomain.com/
  • All forms such as contact forms, login forms, forms in third part components etc all try to send their results to index.php. Since this SEF-routes to http://mydomain.com/ (not http://mydomain.com) all forms would hit a redirection. Since most forms use POST, the redirection would cause the form data to be lost, therefore making your site misbehave: users could not log in, browsing through a list of articles would be impossible, submitting contact forms would redirect you to the home page etc


And that's the long explanation why you can't get rid of the trailing slash.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!