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.

Created a .htaccess to try and change the URL structure, but run into problems?

November 05, 2014 5:31pm

Subscribe [2]
  • #1 / Nov 05, 2014 5:31pm

    Acknowledged74

    7 posts

    Hi

    So I’ve asked within another question so I think it might get lost, really need to sort this out.

    So I’ve created a .htaccess file and uploaded this to my server. This reads

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/system/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) site/$1$2 [R=301,NE,L]

        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ site/index.php/$1 [L]
    </IfModule>

    My intention is that when viewing pages of the site they are in the order URL/subfolder/site/index.php

    or just URL/subfolder/site then the home page shows and the same through the other pages have the template group before page name or indeed instead of the page name when its index.php.

    Please help really stuff, I’m sure its just a small mistake in the .htaccess, but can’t see it.

    Thanks.

  • #2 / Nov 05, 2014 6:05pm

    USC Chan

    81 posts

    You’re still getting mixed up between “index.php”, which is the main PHP file that handles all incoming calls to EE, and the “index” template within a template group. In particular, this line:

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

    is wrong, because it’s set up as if “index.php” is a template within the “site” template group. If you have an incoming call to http://example.com, that’s going to be rewritten as:

    http://example.com/site/index.php

    which is wrong. Leave this line as it is in the example:

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

    and then make sure that the site template group is the default for your site. To do this, go to that template group, then Edit Group, and check the box by “Make the index template in this group your site’s home page?”. Once you’ve done that, an incoming request for your main site home page, say http://example.com, should be rewritten as:

    http://example.com/index.php/

    This will call EE, which will then look for the default template group, which will be Site, and then use the index template in that group.

    For templates which aren’t the default one, it’s similar. Say you have a template group called “oranges”. If you try calling http://example.com/oranges, this should be rewritten by .htaccess as:

    http://example.com/index.php/oranges

    Again, “index.php” here isn’t a template; it’s the file of that name in the main EE install. This will call EE, which will look in the “Oranges” template group for the template called “index”.

    Finally, if you want to refer to a specific *template* (not a template group), it works in the same way. Let’s say you have a template in the “oranges” template group called “jaffa”. You’d call this with http://example.com/oranges/jaffa. This would be rewritten as:

    http://example.com/index.php/oranges/jaffa

    Again, this calls EE, which looks for the “jaffa” template within the “oranges” template group.

    So, try using the example .htaccess file as shown, make sure your “Site” template group is the default for the site, and you should be closer.

  • #3 / Nov 05, 2014 6:37pm

    Acknowledged74

    7 posts

    The reason I added the site/ in was that the EE install isn’t at the route its in a subfolder, as I say

    URL/subfolder/ before we get to site etc. I’m using this:

    https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

    There are various suggestions.

  • #4 / Nov 05, 2014 6:40pm

    Acknowledged74

    7 posts

    the site template group has a * next to it.

    thanks for helping me by the way, I don’t seem to be any closer though, now reads:

    <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /

          # Removes index.php from ExpressionEngine URLs
          RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
          RewriteCond %{REQUEST_URI} !/system/.* [NC]
          RewriteRule (.*?)index\.php/*(.*) site/$1$2 [R=301,NE,L]

          # Directs all EE web requests through the site index file
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    I’ve removed the / from RewriteRule ^(.*)$ index.php/$1 [L] as suggested in the tutorial.

  • #5 / Nov 05, 2014 6:51pm

    USC Chan

    81 posts

    Okay, that does make it a bit clearer, but I think you’re still mixing up the name of the subfolder you’ve got the EE install in, and the name of the default template group. If your subfolder is called “subfolder”, the relevant lines in .htaccess should be something like:

    RewriteRule (.*?)index\.php/*(.*) subfolder/$1$2 [R=301,NE,L]
    RewriteRule ^(.*)$ subfolder/index.php/$1 [L]

    It shouldn’t be necessary to have the name of the default template group in there.

  • #6 / Nov 05, 2014 6:54pm

    USC Chan

    81 posts

    Also, just to be clear, your .htaccess file is in the subfolder where your EE install is, right?

  • #7 / Nov 05, 2014 7:00pm

    USC Chan

    81 posts

    Also, just to be clear, your .htaccess file is in the subfolder where your EE install is, right?

    Actually, ignore the above. I think the suggested rules when you’ve got EE in a subfolder assume that the .htaccess file is in the main folder.

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

ExpressionEngine News!

#eecms, #events, #releases