3

I created a static page using just template files. For example, say I have the following:

/pages/faqs/

The page is accessible via http://www.domain.com/index.php/pages/faqs. What if I wanted the URL to be http://www.domain.com/index.php/foo/? Is there a way to set this?

6

So as with almost everything in EE, there are lots of ways to do this. Here are a few options, roughly sorted by ease of implementation. What's right for you will depend on the complexity of your particular build and your comfort level:

Personally I'd avoid using .htaccess for this kind of static routing, although it will probably work fine it takes routing out of your app and puts it in your server config, which always seems wrong to me when there are native options available.

  • If your foo template is in your site's default template group, and you have "strict URLs" set to off in your global template prefs, your foo template should automatically be available at /foo
  • Use the pages module, creating an entry with a URL of /foo that uses that template.
  • Use an addon like structure, NavEE to manage your navigation/URL structure
  • use a "controller" template as your site's index template, that inspects the URL and routes various values to different template via embeds:

    ... {if segment_1 == "foo"} {embed="pages/foo"} {/if} ...

  • Use Freeway to give you full routing control independent of templating

If you're starting out with EE and/or only need to do this for a few pages, I'd suggest using the pages module in the first instance, as its free, bundled with EE and requires minimal config in order to set up.

If you have a large site or a more complex URL structure with lots of nested/child pages Structure/NavEE are great choices and similarly easy to set up.

| improve this answer | |
  • I'm still confused by Pages Module. Why does it need a channel? If it's connected to a channel, isn't it the same as a channel? I feel I should be using Pages Module, but this relationship to Channel makes me wonder if I am using Pages Module correctly. – ExpressionEngineNewbie Nov 26 '12 at 0:41
  • Because the pages module can be used for different channels and different templates. Not that I would use it that way, I only ever use it for standalone pages that belong to a single channel, but by letting you choose which channel to use with it, it gives you more flexibility. – Tyssen Nov 26 '12 at 1:14
  • 1
    @StackOverflowNewbie the pages module essentially lets you link a channel entry to a URI string and any single template, and basically tells EE, "hey, if you get a request for this URI, serve this channel entry, using this template". It's therefore ideal for static pages (as the name would suggest). If you actually need to serve multiple entries (with URLs like foo/entry_url_title you are better off going with my first suggestion of default template grp + strict URLs off, or freeway or similar if your needs are more complex. – Tom Davies Nov 26 '12 at 7:24
6

Your best bet would be to use either .htaccess, or setup an entry to use that template using the Pages Module.

| improve this answer | |
0

create a .htaccess page in the root of your website and use this:

Redirect 301 /index.php/pages/faq /index.php/foo

alternatively, you code use EE to do the job for you:

create a template called "foo" in your default template group and put this piece of code in that template.

{redirect="pages/faq"}
| improve this answer | |
0

Someone pointed out freeway on another question, and this seems to also do what you are asking for.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.