ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

.htaccess for removing template group

December 14, 2011 12:43pm

Subscribe [1]
  • #1 / Dec 14, 2011 12:43pm

    TJ Draper

    222 posts

    So I came up with an ingenious plan to automatically create short URLs for articles posted on an ExpressionEngine site. The first site I’m trying this on is one of my own. The url is http://appleuserpro.com  so I set up the domain name aupro.us.

    In ExpressionEngine I created a template group called “u” and used the following code in the template:

    {preload_replace:channel="appleuserpro"}
    
    {exp:channel:entries channel="{channel}"}
    
    {if segment_1!=""}<meta HTTP-EQUIV="REFRESH" content="0; url=http://appleuserpro.com/article/{url_title}">{/if}
    
    {if segment_1==""}<meta HTTP-EQUIV="REFRESH" content="0; url=http://appleuserpro.com">{/if}
    
    {/exp:channel:entries}

    Then I copied my index.php and .htaccess file to the root of the new short url domain and used the assign to config lines to set template group and template to my URL shortener template.

    The problem is I tried using .htaccess to remove the template group “u” from my URLs but I have been unsuccessful. It works if I stick with removing index.php and include the template group in the URL: http://aupro.us/u/790

    But trying to remove the “u” using .htaccess results in 404 errors. I’m not sure why this isn’t working. Any ideas?

    Here’s my .htaccess file

    DirectoryIndex index.php
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>

    And I tried different variations of adding u like so:

    RewriteRule ^(.*)$ /index.php/u/$1 [L]

    I’ve tried with and without the trailing slash but to no avail. There must be a way to do it. I’d rather not include the template group in the short URL. Any advice for me?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases