Pretty URLs Setup Problems

There was a forum thread back in September with some issues struggling to get pretty URLs implemented. I have a similar issue, but now that we’re months further down the development line, and Elements has progressed so far since September, I wanted to start a new thread.

I’m working on my first Elements CMS blog for HX Aviation. I’ve used Elements Essentials and followed a few of the older YouTube tutorials to get everything up and running.

I have four posts ready to go live, and when I do a local preview, everything looks perfect!

My next step is to get it over on my development site. That’s when things start to go wrong. I’ve spent 3 hours trying to get this to work, and I’m hoping more experienced eyes will quickly spot my error.

My ideal “Pretty url” for each blog post would be: https://flyhxaviation/articles/post-title-here

I added the rewrite code to the .htaccess file, but the individual posts return 404 errors.

Here is the current version of my .htaccess (which is a the root of the subdomain for the dev site). I attempted to use the rewrites in the Elements documentation and the below is from ChatGPT.

RewriteEngine On

# 1) Redirect query URL -> clean URL
# /articles/?item=slug  (or /articles/index.php?item=slug) -> /articles/slug
RewriteCond %{THE_REQUEST} \s/articles/(index\.php)?\?item=([^&\s]+) [NC]
RewriteRule ^articles/?$ /articles/%2? [R=301,L]

# 2) Internally rewrite clean URL -> CMS handler
# /articles/slug -> /articles/index.php?item=slug
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([^/]+)/?$ articles/index.php?item=$1 [L,QSA]

And here are the settings in the Collection component:

I hope I just screwed something simple up and this will all be up and running with some tweaks.

Thanks in advance for your generosity helping me figure this all out.

Hi @chet

I checked the development site and can see that the individual post pages are working with query parameters: Trusted Aircraft Brokerage & Sales | HX Aviation, LLC Copy Copy

The short version is: the rewrite rules don’t match the actual URL structure on your dev site.

On the dev site the CMS posts actually live at /hx/cms/post/{slug} not under /articles at all.

So the core issue is:

  • Your .htaccess rules are written to handle /articles/{slug}
  • But the real request path on the dev domain is /hx/cms/post/{slug}
  • Because Apache evaluates rewrite rules relative to where the .htaccess lives, none of the patterns ever match
  • Result: the rewrite never fires → 404

That’s why the query-string version works:

/hx/cms/post/?item=mastering-the-pre-purchase-inspection

but the “pretty” version does not.

To fix it, the rewrite scope and the actual CMS path need to line up — either by:

  • moving the .htaccess into /hx/cms/ and rewriting relative to post/, or
  • keeping it at the subdomain root and explicitly matching /hx/cms/post/{slug}

Once those match, the CMS handler will resolve the post correctly.

Hope that helps :slight_smile:

Yes, that’s very helpful!

With some more tinkering, I was able to get the pretty URLs that I was looking for, but this created other problems. The blog post page stripped out all of the spacing and the images on the page were all broken. My links (like the button to go back to the Articles page) would rewrite incorrectly and 404.

Some of this may be just the dev site and fixable on the production site, but I don’t really want to risk breaking something on the live site over how the URL looks.

I’m not a fan of Wordpress, but the one feature that I always appreciated was the ability to simply type in the post slug I wanted and WP did all the heavy lifting. I don’t know if that’s technically feasible for the Elements system, but it would be very nice.

Agree strongly - ability to supply a definitive slug like WP would be great