Author Topic: Hide "page" directory and "php" extension  (Read 23495 times)

Offline cosmorphis

  • Posts: 3
Hide "page" directory and "php" extension
« on: October 06, 2009, 01:15:25 AM »
Just want to say, after I've discovered WebsiteBaker, I've been using it for all my CMS needs. Easy to use, install, maintain, create templates for, etc., and especially easy for my clients!! All the others are so freaking complicated.

Well, what I've been wanting to do for awhile is:

- Remove the "page" directory from the URL
- Remove the ".php" extension from the URL

Instead of my links looking like http://domain/pages/about-us.php I would like them to look like http://domain/about-us

I think it would make it a lot more professional looking. I have been doing some searches, and a lot come up under the German section, and well, I don't speak/read German.  :-P I know it would involve:

- Editing the .htaccess file
- Editing the template (show_menu) to spit out the URLs as modified

I can easily make WebsiteBaker use the root directory to remove the pages directory, but that seems to be ill advised. I know if I take the time to read and learn, I could probably get it going myself--I'm just a little over whelmed trying to stay on top of typography, html, css, photoshop, actionscript, javascript, php, mysql, etc.

If there is a canned solution, or this has been done already, I would really, really appreciate a point in the right direction.

Thanks!

Online crnogorac081

  • Posts: 1852
  • Gender: Male
Re: Hide "page" directory and "php" extension
« Reply #1 on: October 06, 2009, 09:30:21 AM »
If you remove folder PAGES, and place your pages in root (www.mysite.xy/page1.php) you will not be able to add more pages in root, unless you set permissions to 777 when you want to do that..and when you are done you will need to return permissions to 755.. While you have 777, you are vunerable to any hacker atemp.. that is why this is not advised..

Regardint revriteing .php to .html , there is a  htaccess.txt in instalation package, which needs to be revrited to .htaccess if you want pages to be .html

cheers
no bb in signature

Offline kweitzel

  • Posts: 6983
  • Gender: Male
    • Weitzel EDV - multilingual IT services
Re: Hide "page" directory and "php" extension
« Reply #2 on: October 06, 2009, 11:50:38 AM »
Quote
If you remove folder PAGES, and place your pages in root (www.mysite.xy/page1.php) you will not be able to add more pages in root, unless you set permissions to 777 when you want to do that..and when you are done you will need to return permissions to 755


This is not entirely right, it depends on your server configuration if it works or not! And there is no "out of the box" solution which you can "just" enable.

1) Pages folder: should be removed before adding any pages, otherwise you need to manipulate the whole site structure, access files, database and so on ...

Check out apache mod_rewrite rules to get rid of the pages folder "on the fly" without changing the structure. Haven't tried it myself though

Try this solution: http://www.websitebaker2.org/forum/index.php/topic,14455.0.html ... but no warranty that it works for you.

cheers

Klaus
WebsiteBaker Org e.V. - for WebsiteBaker


Offline Luisehahne

  • WebsiteBaker Org e.V.
  • **
  • Posts: 4037
  • Gender: Male
    • Webdesign und Entwicklung WebsiteBaker
Re: Hide "page" directory and "php" extension
« Reply #3 on: October 06, 2009, 12:23:25 PM »
I think you need a change to shortlink. I know, there is something in development.

Dietmar
Eric T. Hansen, amerikanischer Buchautor „Nörgeln des Deutschen größte Lust"
Neues Unwort: Schnappatmung

Offline Hans>NULL

  • Posts: 1386
  • Gender: Male
/dev/null Ort ohne Wiederkehr

Offline cosmorphis

  • Posts: 3
Re: Hide "page" directory and "php" extension
« Reply #5 on: October 08, 2009, 06:08:34 AM »
Here is what I have so far. I know it's crude, and might break further down the road, but since nobody has any solution, I figured this would be a good starting point:

For the .htaccess file:
Code:
Only registered users can see contents. Please click here to Register or Login.
For the ..\framework\class.wb.php file:

Code:
Only registered users can see contents. Please click here to Register or Login.
Explanation:

I don't want to really change the structure of the site, just how it appears in the links. What the .htaccess file is doing is monitoring the INCOMING urls, but actually grabbing the correct URL. For instance, the URL http://www.domain.com/test is coming in, but Apache is actually grabbing and throwing up http://www.domain.com/pages/test.php. So all the original links work, and the new ones as well.

Now, how do we make all the navigation links look nice as well? I went into ..\framework\class.wb.php and changed how the page_link function is utilized. Everytime WebsiteBaker uses the page_link function, it is displayed without the "page" directory and without the ".php" extension.

Now, I don't make any promises that will this work on your site, or for me later on down the road. I was just too excited that I found a potential solution, that I had to post it up!  :-D

Online crnogorac081

  • Posts: 1852
  • Gender: Male
Re: Hide "page" directory and "php" extension
« Reply #6 on: October 08, 2009, 09:43:04 AM »
Hi,

So now links to the files are displayed like it is folder.. Am I right ?

Also, I will test this too.. Caould anyone else test this ?

all best
ivan
no bb in signature

Offline cosmorphis

  • Posts: 3
Re: Hide "page" directory and "php" extension
« Reply #7 on: October 13, 2009, 09:33:37 AM »
So yes, the goal is to display the URLs as folders. Here is my updated .htaccess file, with comments:

Code:
Only registered users can see contents. Please click here to Register or Login.
If anybody has anything to add, feel free! I know this code is amateur at best, but heck, it's the only thing I've found on the internet!

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Hide "page" directory and "php" extension
« Reply #8 on: October 13, 2009, 02:42:49 PM »
Hello 'cosmorphis',
I didn't test your code yet.

I wonder what happens to pages like account/login.php, account/forgot.php
and also what happens to the SEARCH if it is in use.

Kind Regards,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Online crnogorac081

  • Posts: 1852
  • Gender: Male
Re: Hide "page" directory and "php" extension
« Reply #9 on: October 15, 2009, 01:46:06 AM »
So with this .htaccess rewriteing, there is no need to rewrite framework file ..\framework\class.wb.php ??

cheers
no bb in signature

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Hide "page" directory and "php" extension
« Reply #10 on: October 20, 2009, 12:05:40 PM »
What happens if you have a page called Templates, or Pages, or Media, etc?
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline LordDarkman

  • Posts: 343
  • Gender: Male
  • Leben ist schön. Nur nicht drüber nachdenken...
    • Internet Radio Gates of Doom
Re: Hide "page" directory and "php" extension
« Reply #11 on: October 21, 2009, 02:24:15 AM »
I tested the solution with win2008Server... funny mess. So I can tell it just works with apache not with IIS.
So I thing there should be an other solution because not everyone is useing apache (most but not all). Maybe Hans>NULL can test it also on his server. I thing it's a gread thing if it works.

CU Moritz

Offline ChrusR

  • Posts: 46
  • Gender: Male
Re: Hide "page" directory and "php" extension
« Reply #12 on: August 09, 2010, 05:19:11 PM »
Well, what I've been wanting to do for awhile is:
- Remove the "page" directory from the URL
- Remove the ".php" extension from the URL
I'm really interested to know if this is on the Roadmap for a future WSB-Version (out of the box support). I know the Short Url Hack (a really nice hack), but it is not supported by all modules and lacks special charaters URLs (like "Füße") and ending slash (dir) support.
I fear that the concept of WSB  and its modules is not designed to make this easy available out of the box (I'm not a coder). Many say, that it is not needed for SEO, but I think it would be very useful for replacing existing sites and for nice URLs (quoting in Mails, print, etc.). I know that there is the ReWrite-possibility, but I think it would be better if the WSB-core will support this.
If someone can make a statement about the WSB-concept on this features (no way, possible, planned, in development)?
Testing WB since June 2010. HMTL & CSS Knowledge, some JS-Hacking, no real PHP & SQL-Knowledge.

Offline lausianne

  • Betatester
  • **
  • Posts: 205
    • Webdesign Burgdorf
Re: Hide "page" directory and "php" extension
« Reply #13 on: August 12, 2010, 03:32:25 PM »
Hi there,

yes I agree, this would be a very nice feature. Mostly people don't care much, because they understand little and believe the URL must be like that and never ask. But I have a few clients who care and want "pages" removed and have their URLs as short as possible.

Even if it doesn't matter for SEO. When URLs are stored or forwarded or quoted, it does matter - if only aesthetically.

Cheers,
Ralf.

Offline ChrusR

  • Posts: 46
  • Gender: Male
Re: Hide "page" directory and "php" extension - clean short URLs
« Reply #14 on: August 15, 2010, 09:20:02 AM »
But I have a few clients who care and want "pages" removed and have their URLs as short as possible.
Even if it doesn't matter for SEO. When URLs are stored or forwarded or quoted, it does matter - if only aesthetically.
Exactly. And call me paranoid, but I think the URL system can be used by malicous crawlers (f.e. in the case of serious bugs) to recognize the CMS. In every other point WSB is very flexible; AFAIK (as non-coder) the "ghost-php-files writing of the sitemap" in the pages folder is the base concept, that makes it difficult to code a compatible solution (I guess I understand that from some answers in the forum). Maybe this concept has to be reviewed; for me it would be very interesting to understand, what are the main advantages of the actual WSB-pages concept and naturally what the (near) future can bring. And I hope that the wish in this Topic would be considered as a main WSB-feature-improvement.
Testing WB since June 2010. HMTL & CSS Knowledge, some JS-Hacking, no real PHP & SQL-Knowledge.

Re: Hide "page" directory and "php" extension
« Reply #15 on: September 29, 2010, 09:48:49 PM »
I'm not as interested in removing the extension, but I've definitely wanted the pages directory removed from URLs. After quite some work I've put something together that works for me and should for others too:
http://westhouseit.co.uk/topics/WebsiteBaker-remove-pages-from-url.php

Let me know what you think and I'll make any changes needed to get it working properly. I'm also going to get in touch with the WB dev team to see about putting some of this into the core code.
« Last Edit: September 29, 2010, 09:59:40 PM by Paul - Westhouse IT »
Westhouse IT - Professional WebsiteBaker developers for hire.

Offline Ruud

  • WebsiteBaker Org e.V.
  • **
  • Posts: 3580
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Hide "page" directory and "php" extension
« Reply #16 on: September 29, 2010, 11:31:23 PM »
Just removing the /pages from the (advanced) settings is a solution that will technically work fine for most.
A huge WARNING is needed here..

By doing this, you will need to explain your users/webmasters/customers they are not allowed to make certain pages.

Creating a page called "config" or "admin" or "framework" or any other existing directory or filename in the WB package will crash the website instantly.

For me that is the main reason for not doing that. I cannot tell my customers "Here you have this user-friendly website, and here is a list of all things you are not allowed to do"
If you do not like /pages try using /html or /{my-language} or /doc /user and so on..

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Hide "page" directory and "php" extension
« Reply #17 on: September 30, 2010, 01:08:25 AM »
By doing this, you will need to explain your users/webmasters/customers they are not allowed to make certain pages.
...
For me that is the main reason for not doing that. I cannot tell my customers "Here you have this user-friendly website, and here is a list of all things you are not allowed to do"
If you do not like /pages try using /html or /{my-language} or /doc /user and so on..

Hello,

wouldn't it be possible to provide a feature (may be a admin-tool) where you can make some restriction depending on filenames (page filenames).
So once set, there comes a massage "please choose another name, for {{name}} is allready reserved for the system".

It doesn't seem to be too hard to do?
Or a automated function, where the media... Constants and also framework/... etc. will be checked while creating a new site at this level(0) and the pages Constant is empty.

Regards,
Stefek
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Offline Luisehahne

  • WebsiteBaker Org e.V.
  • **
  • Posts: 4037
  • Gender: Male
    • Webdesign und Entwicklung WebsiteBaker
Re: Hide "page" directory and "php" extension
« Reply #18 on: September 30, 2010, 03:07:08 AM »
Quote
wouldn't it be possible to provide a feature

is already in work, handle in core

Dietmar
Eric T. Hansen, amerikanischer Buchautor „Nörgeln des Deutschen größte Lust"
Neues Unwort: Schnappatmung

Offline Hans Toolbox

  • Posts: 910
Re: Hide "page" directory and "php" extension
« Reply #19 on: September 30, 2010, 03:55:57 AM »
so isset (so is it  :-D )
« Last Edit: September 30, 2010, 03:57:41 AM by Hans Toolbox »
[Die Beleidigung gegenüber mir wurde durch mich gelöscht, User wurde von mir ausgeschlossen - kweitzel]

Re: Hide "page" directory and "php" extension
« Reply #20 on: September 30, 2010, 09:22:49 AM »
Just removing the /pages from the (advanced) settings is a solution that will technically work fine for most.
A huge WARNING is needed here..

By doing this, you will need to explain your users/webmasters/customers they are not allowed to make certain pages.

Creating a page called "config" or "admin" or "framework" or any other existing directory or filename in the WB package will crash the website instantly.

Yes, it likely would crash in the case where /pages isn't used at all. My solution keeps content under /pages, but uses rewrites to find content. A problem would occur with pages/directories named the same as existing ones, but it would result in a redirection that mostly loops around to the main index page. So the result would be an unreachable page, but not a site failure.
Westhouse IT - Professional WebsiteBaker developers for hire.

Offline Tango

  • Posts: 13
Re: Hide "page" directory and "php" extension
« Reply #21 on: June 10, 2015, 07:53:32 PM »
Hi guys,

I've found a way to hide the .php extension from pages using the .htaccess file, as it follows:
Code:
Only registered users can see contents. Please click here to Register or Login.
However, there's a problem with adding this, as you won't be able to login in the admin and some modules will stop working (like BAKERY).
So is there any way we can make this redirect work, without changing any core files?