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 issue on EE 2 as opposed to EE 1

November 12, 2012 2:17pm

Subscribe [1]
  • #1 / Nov 12, 2012 2:17pm

    Linda A

    666 posts

    Something seems to have changed between EE 1 and EE 2 in terms of what sort of URLs are accepted. On EE 1, I was using the following .htaccess rewrite successfully:

    RewriteRule ^/?((403|404|Contact|Search)(/.*)?)$ /Westeros/$1 [L]
    RewriteRule ^/?((Digest|Updates|Westeros)(/.*)?)$ /index.php/$1 [L]

    This allowed me to have http://www.westeros.org/Search/, for example, even though “Search” is a template in the “Westeros” template group, rather than needing http://www.westeros.org/Westeros/Search/. The same for 403, 404 and Contact, they’re all templates in the Westeros template group.

    Is there any way of accomplishing this in EE 2?

  • #2 / Nov 14, 2012 3:13pm

    Dan Decker

    7338 posts

    Hi Linda,

    Is “Westeros” your default site template group? Meaning, is it the template group that holds the site’s index template?

    Are you using Strict URLs? I don’t think much changed with URI handling in EE 1 to EE 2, but if Westeros is your default group, you wouldn’t need the rewrites at all. EE assumes {segment_1} is either a template group, a template in the default group, or an entry_id/url_title to be handed to the default index template.

    Tell me a bit more about Westeros and I think we can find a way to get you back to good on this.

    Cheers,

  • #3 / Nov 14, 2012 3:28pm

    Linda A

    666 posts

    No, Westeros isn’t actually the default. However, I am not using Strict URLs, either.

    It seems that EE 1 allowed the template group to be written out via .htaccess, whereas EE 2 seems to put a stop to that. I don’t know a lot about .htacceess, I had help putting these together, but it seems really odd to me that EE can actually stop that from working. After all, shouldn’t the .htaccess basically change http://www.westeros.org/Search/ into first http://www.westeros.org/Westeros/Search/ and then http://www.westeros.org/index.php/Westeros/Search/ ?

    The rewrites to take out index.php seem to work fine, so I am baffled at how it can put a stop to writing out the template group. I should add that I did migrate some of these templates to Pages to avoid this sort of rewrite, but the remaining ones include forms (like Search) so they can’t be made into Pages. And I would really want to avoid, if at all possible, having to make a Search template group for a single template.

  • #4 / Nov 16, 2012 3:23pm

    Dan Decker

    7338 posts

    Hi Linda,

    A Page in the pages Module can point to a template with other ExpressionEngine tags in it - like a search page. Then you can map the URI to where you want it to go.

    Does that help?

    Cheers,

  • #5 / Nov 16, 2012 6:43pm

    Linda A

    666 posts

    Oh, I hadn’t thought of that. So in theory, a Page doesn’t have to have any content of its own, it could just map to a template?

  • #6 / Nov 19, 2012 1:53pm

    Linda A

    666 posts

    Well, I am hitting a snag here with Pages too.

    I run two sites (using the old method) off my EE installation. So, I have two Search pages, one for each site. Since Pages have to have different URI, my solution on EE 1 would have been to give them URIs such as /Westeros/Search/ and so on.

    But, that no longer works on EE 2 either as it falls afoul of the same .htaccess rewrite issue as above. And I just don’t get why. Here’s the whole relevant .htaccess section:

    RewriteRule ^/?((403|404|About|Contact|Copyright|Search)(/.*)?)$ /Westeros/$1 [L]
    RewriteRule ^/?((Images|Index|Digest|Updates|Westeros)(/.*)?)$ /index.php/$1 [L]

    403, 404, Contact and Search are templates in the Westeros template group. About and Copyright are Pages with an URI of /Westeros/About/ and /Westeros/Copyright/.

    Images, Index, Digest, Updates and Westeros are template groups.

    This code worked on EE 1. Search could be accessed at http://www.westeros.org/Search/ and About could be accessed at http://www.westeros.org/About/

    But on EE 2, neither the Templates nor the Pages work unless the Westeros part is included. I also tried this approach to make sure it was all done in one step, but that doesn’t work either:

    RewriteRule ^/?((403|404|About|Contact|Copyright|Search)(/.*)?)$ /index.php/Westeros/$1 [L]
    RewriteRule ^/?((Images|Index|Digest|Updates)(/.*)?)$ /index.php/$1 [L]

    I should add that the index.php rewrite as such works, because I can access http://www.westeros.org/Updates/ just fine.

     

  • #7 / Nov 19, 2012 5:51pm

    MadWebDesigns

    147 posts

    Hi Linda,

    Can you post the entire contents of your htaccess file please so we can have a look.

    Thank you,

    Mike

  • #8 / Nov 19, 2012 6:19pm

    Linda A

    666 posts

    There’s a lot of stuff in there that probably isn’t relevant, so what I will do is strip down to just this relevant stuff and test with that. If it makes no difference, I will then pass that along in just a few. 😊

  • #9 / Nov 19, 2012 6:27pm

    Linda A

    666 posts

    Alright, here it is.

    <Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    
    <Files index.php>
    AcceptPathInfo on
    </Files>
    
    AddType application/x-httpd-php .html
    
    CheckSpelling On 
    
    DirectoryIndex index.php
    
    ErrorDocument 403 <a href="http://www.westeros.org/403/">http://www.westeros.org/403/</a>
    ErrorDocument 404 <a href="http://www.westeros.org/404/">http://www.westeros.org/404/</a>
    
    Options -Indexes
    
    
    RewriteEngine on
    
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(.*\.)?westeros.org/.*$   [NC]
    RewriteCond %{HTTP_REFERER} !^http://(.*\.)?hippoiathanatoi.com/.*$  [NC]
    RewriteRule \.(gif|jpg|png|mp3)$    -      [F,NC,L]
    
    RewriteRule ^/?((403|404|About|Chat|Contact|Copyright|Search)(/.*)?)$ /index.php/Westeros/$1 [L]
    RewriteRule ^/?((ASoIaF|Digest|Images|Login|Store|Updates|member)(/.*)?)$ /index.php/$1 [L]
    
    RewriteRule ^/?(.*)RSS10(.*)$ /$1RSS20$2 [R=301,L]
    
    RewriteRule ^/?(.*)Section/(\d\d?)\.(\d\d?)\.(\d\d?)\.(\d\d?)\./?$ /$1Section/$2_$3_$4_$5_/ [L]
    
    RewriteRule ^/?(.*)Characters/Entry/Ser_(.*)$ /$1Characters/Entry/$2 [L,R=301]
  • #10 / Nov 21, 2012 7:00am

    Linda A

    666 posts

    Any other thoughts? Someone pointed me to a blog post from Pixel & Tonic (http://pixelandtonic.com/blog/making-pt-structure) which included a rewrite example:

    RewriteRule ^index.php/(playa|wygwam|fieldframe|ffmatrix)(/[^\/]+)?(/.+)?$ /index.php/ee$2/$1/$3 [NC,L]
    
    This little redirect (coupled with a standard index.php redirect) will take an incoming URI like /playa, and turn it into /index.php/ee/playa behind the scenes.

    I just can’t figure out if that can apply to my situation, in part because I don’t quite see why he’s starting the rule with index.php when he says the incoming URI will be /playa. I also don’t see why its /ee$2/ and not just /ee/. But from the description it is doing what I need, allowing for a template group to be removed. It seems like that would also work for part of a Page URI, unless something internally prevents that.

    Edited to add: I found http://htaccess.madewithlove.be/ and tested my .htaccess with it. According to it, it does rewrite http://www.westeros.org/About/ to http://www.westeros.org/index.php/Westeros/About/. How can EE fail to recognize that? Doesn’t the rewrite happen before it even takes a look at the URL?

  • #11 / Nov 21, 2012 12:32pm

    Dan Decker

    7338 posts

    Let’s just get a look - I’d like to try a few things. Be on the lookout for an email from EllisLab!

    Cheers,

  • #12 / Nov 21, 2012 12:40pm

    Linda A

    666 posts

    Thank you Dan, I’ve sent stuff along with just a few additional notes. It is a bit of a confusing setup at points, so if you need any more info, just let me know.

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

ExpressionEngine News!

#eecms, #events, #releases