I'm porting an existing site to CMSMS 1.9.3, and I'm using pretty URLs to maintain the existing (hierarchical) page organization. It's gone well (great tool!), but I have one issue: URLs that end with "/" aren't treated as the same as the same URLs with "index.html" appended.
This is how Apache treated my old website, and I'd like to continue it so that people's bookmarks continue working. But the default page appears at mySite.com/, but not mySite.com/index.html. And, other index pages I've created appear at mySite.com/myCategory/index.html, but not mySite.com/myCategory/.
Yes, I could create a redirect page for every directory, but that's painful and error-prone.
Any suggestions?
Thanks,
Dan
Pretty URLs and ".../" == ".../index.html" [SOLVED]
Pretty URLs and ".../" == ".../index.html" [SOLVED]
Last edited by dtgriscom on Tue Mar 08, 2011 4:16 pm, edited 1 time in total.
Re: Pretty URLs and ".../" being equivalent to ".../index.ht
Apache supports priority of index.* files... When my site is "Coming Soon" I set index.html to take top priority (with the coming soon message).. When my site is live, I set index.php to take top priority. I don't know how to set it manually, but there is the option in my hosting control panel for this.
You can do some mod_rewrite magic in your .htaccess file to remove all index.html references from the requesting URL. I don't know how to do it off the top of my head.. I have to look it up each time.
You can do some mod_rewrite magic in your .htaccess file to remove all index.html references from the requesting URL. I don't know how to do it off the top of my head.. I have to look it up each time.
Re: Pretty URLs and ".../" being equivalent to ".../index.ht
Actually, I need the opposite: URLs that end in "/" should have "index.html" appended. I'm sure it could be done with mod_rewrite, although that's one learning curve I have yet to climb. Unfortunately, this would mean that the default page (which always lives at "mysite.com/") would never be visited, which is workable albeit grody.
(Switching index.html and index.php priorities wouldn't work, since for CMSMS to work it all has to be routed through index.php.)
Given how common this feature is on Apache-only websites, it would be great if there were a CMSMS option that did this for us. Any ideas?
(Switching index.html and index.php priorities wouldn't work, since for CMSMS to work it all has to be routed through index.php.)
Given how common this feature is on Apache-only websites, it would be great if there were a CMSMS option that did this for us. Any ideas?
Re: Pretty URLs and ".../" being equivalent to ".../index.ht
You can do mod_rewrite to add .html to the end/extension of all pages but unlike flat file sites you can't have mysite.com/some category/index.html ans mysite.com/another category/index.html as this system doesn't use folders for sections/categories like a flat file system...
You will have to redirect all incoming URLs to the new pages in a .htaccess file...
You will have to redirect all incoming URLs to the new pages in a .htaccess file...
Re: Pretty URLs and ".../" being equivalent to ".../index.ht
Well, I finally fixed it all with mod_rewrite. Here's my new .htaccess file:
Took a while to build (using successive approximation programming), but it seems robust now.
Thanks,
Dan
Code: Select all
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteBase /
# Rewrite top level "index.html" page and empty query
# to the default page for the website
RewriteRule ^index.html$ index.php?page= [QSA,L]
RewriteRule ^$ index.php?page= [QSA,L]
# URLs ending in ".html" will be mapped to index.php with argument
# but only if the requested URL is not a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
# If request ends in slash, assume it's a directory and get its index
RewriteRule ^(.+)/$ index.php?page=$1/index [QSA,L]
# If we haven't remapped anything, and the URL isn't a file,
# try assuming it's a CMS directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1/index [QSA,L]
# Anything else will fall through
Thanks,
Dan
Re: Pretty URLs and ".../" being equivalent to ".../index.ht
A few more tweaks and improved comments:
Code: Select all
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteBase /
# Rewrite top level "index.html" page and empty query
# to the default CMS page
RewriteRule ^index.html$ index.php?page= [QSA,L]
RewriteRule ^$ index.php?page= [QSA,L]
# Allow access to admin area via "admin"
RewriteRule ^admin/?$ admin/index.php
# URLs ending in ".html" will be mapped to index.php with argument
# but only if the requested URL is not a real file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+).html$ index.php?page=$1 [QSA,L]
# If request ends in slash, assume it's a CMS directory and get its index
RewriteRule ^(.+)/$ index.php?page=$1/index [QSA,L]
# If we haven't remapped anything, and the URL isn't a real file,
# try assuming it's a CMS directory. This will also ensure that
# any bad URL go through the CMS and display the CMS error page.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1/index [QSA,L]
# References to files (e.g. images) will fall through.
Re: Pretty URLs and ".../" == ".../index.html" [SOLVED]
Well, I found another bug in my redirect code, so here's my latest shot:
(Boy, would it be nice if CMSMS handled this internally...)
Code: Select all
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteBase /
# Rewrite top level "index.html" page and empty query
# to the default CMS page
RewriteRule ^index\.html$ index.php?page= [QSA,L]
RewriteRule ^$ index.php?page= [QSA,L]
# Allow access to admin area via "admin"
RewriteRule ^admin/?$ admin/index.php [L]
# URLs ending in ".html" will be mapped to index.php with argument
# but only if the requested URL is not a real file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ index.php?page=$1 [QSA,L]
# If request ends in slash, assume it's a CMS directory and get its index
RewriteRule ^(.+)/$ index.php?page=$1/index [QSA,L]
# If we haven't remapped anything, and the URL isn't a real file,
# add a slash at the end and try again. This will also ensure that
# any bad URL go through the CMS and display the CMS error page.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1/ [R]
# References to files (e.g. images) will fall through.