Forum

Thread tagged as: Api

Extensionless URL's

Hi all,

We're almost finished with our first Perch website! One thing that we want to do is to provide extensionless URL's, and for the blog we want to provide we want to change the format from e.g. /blog/post.php?s=[date]-[title] to /blog/[date]/[title].

I know that there is a 'hide-extensions' option on navigation and custom content, however this doesn't remove extensions from a link that a content editor may have inserted that links to another page in perch. Yes, I could mention to the content editor that they should never enter the .php extension, but that leaves it very open to human error, plus we use the PagesList field type in quite a few places, which of course creates the link automatically - the content editor doesnt type in the URL.

The only achievable method I can think off is using one of Apache's proxy modules to modify the HTML before serving it to the client, but I am far from an expert with Apache.

Has anyone had any success with this? Or any advice on another approach?

Many thanks Al

Al Higgs

Al Higgs 1 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Why would a content editor know those URLs existed if you had rewritten the URLs?

If you have mod_rewrite available then rewrite the URLs as described in the docs, then any copy and pasted URL will be the rewritten one.

https://docs.grabaperch.com/video/v/simple-url-rewriting/

Hi Rachel,

Thanks for your response.

Take this example. We have a page, that in the sidebar the Content Editor can add a "Call to action", and link it to a page. The link is chosen using the PageList field type. We specify it in our content template like so:

<a class="animated-chevron" href="<perch:content id="page" type="pagelist" label="Page" order="3" required="true" />">Learn more</a>

This renders a hyperlink that looks like so:

<a href="/services/user-experience.php" class="animated-chevron">Learn more</a>

So, whether it's the contetn editor, the end-user, or a search engine bot, they are going to see the .php extension. We can rewrite it and force 301's from url's with .php extensions, but that's not a solution, hence I was thinking about an Apache module to modify the HTML before sending it back to the client.

Any thoughts?

Thanks Al

I've previously used this https://forum.grabaperch.com/forum/10-09-2014-add-hideextensions-to-the-pagelist-fieldtype (you need to modifiy the pagelist fieldtype file)