Forum

Thread tagged as: Question, Configuration, Meta

Newbie Questions

I'm planning on digging my teeth into Perch over the weekend and I have a few questions to ask that will get me heading in the right direction. Looking through some of the documentation I couldn't find clear answers.

  1. Remove/do not display the .php extension in the page slug/url.

  2. When creating new pages can I have a different page name and page slug/url and possibly create a tag in the SEO template for the editor to enter the page slug/url?

  3. Navigation, what is the best approach to setting up the Navigation so an editor can enter the nav label when they are creating a new page from a Master Page Template?

Thank you for any guidance!

Bob

Bob Hafemeister

Bob Hafemeister 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. The navigation functions all have a hide-extensions option for not outputting the extension in generated links:

https://docs.grabaperch.com/docs/navigation/perch-pages-navigation/

Then you just need a rewrite rule to match the non-extension links to the real file names:

https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

  1. I'm not quite sure what you mean here. You can name your pages whatever you like!

  2. They can do that - it's the Navigation Text field.

Drew,

Thanks for getting back to me so quickly.

If I wasn't going to utilize the Perch navigation is there a way to hide the page extensions site wide? I use Nginx so I'm not using .htaccess but I can setup the re-write rules in my host.conf file.

I see the Navigation Text field, I was getting mixed up with navigation groups but I get it now.

Thanks again!

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you're generating your own navigation, then you can just remove the .php when you output the links. Nothing special needed in Perch.

Nginx is no problem.

Thank you!

Drew,

To hide the .php extension in Nginx for SEF do you know what the proper rewrite code is? No matter what I do the .php extension is still shown in the url.

location / { try_files $uri $uri/ /index.php?page=$request_uri; }

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where is it coming from? The server rewrite rules will only affect the mapping of a non-exention URL to the actual page. It won't change the links in your page.

So what is the best way to not display the .php extension? In Modx I enable their Pretty URL's, is there a config setting in Perch?

Thanks

Bob

Rachel Andrew

Rachel Andrew 394 points
Perch Support

I'm not sure where these links are coming from? You said you are creating your own Navigation, so you would just link pages without the extension if you are writing your own link in the HTML. That has nothing to do with Perch, we don't rewrite HTML you enter.

If you are generating Navigation from within Perch then Drew explained how you stop Perch outputting the extension.

Rachel,

If I use the Perch Navigation then it works but when I use hard links like below no matter what I do the url has .php Ex: contact.php

<ul class="dropdown-menu"> <li><a href="contact">Full Width</a></li> <li><a href="about">About</a></li> <li><a href="services">Services</a></li>

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Your server must be redirecting rather than rewriting the link then - it isn't anything to do with Perch.

Rachel,

I figured it out, not sure if this is the best solution but it works.

Thank you for your help.

location / { #try_files $uri $uri/ /index.php?page=$request_uri; try_files $uri.html $uri/ @extensionless-php; }

    location ~ \.php$ {
            include fastcgi_params;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location @extensionless-php {
            rewrite ^(.*)$ $1.php last;
    }