7

I've had a similar question up on Stack Overflow, but now that we've got this shiny new site, I figured I might as well bring it here.

With EE 2, is it possible to remove anything other than index.php from the URLs via .htaccess rewrites? I am thinking of, for example, a non-default template group or part of a Page URI.

Both these things could be done in EE 1 but no longer work for me in EE 2. I have tested my rewrites using http://htaccess.madewithlove.be/ and as far as I can tell, they do result in the correct URLs. However, attempts to access the pages lands me on my default page.

My original setup was this:

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

I've also tried this:

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]

There's a couple of different things going on and some work and some don't, in both of these scenarios.

1) domain.com/Updates/ works fine. Updates is a template group. So, no problems with just removing index.php.

2) domain.com/Search/ does not work. Search is a template within the Westeros template group. It does work to access it as domain.com/index.php/Westeros/Search/. The reason for this rewrite is that I wanted to avoid creating several single-template template groups to handle things like Search, Contact, etc. At the same time, its important that these segments come right after the domain given the overall structure of the site.

3) domain.com/About/ does not work. About is a Page with its URI set to /Westeros/About/. It does work to access it as domain.com/index.php/Westeros/About/. Again, I need these Pages to display right after the domain to fit into the overall structure of the site, but since I am running multiple sites using the old method (multiple index.php files) rather than MSM, I cannot simply make the URI /About/ for the Page since I have an /About/ Page for each site/subsite.

In case .htaccess can't be used for this any longer in EE 2, are there any other options available for these sort of behind-the-scenes URL changes?

Edited to add: I have now received a support answer from EE on this matter and even though removing the template group is unsupported, they pointed to a config option that has restored the EE 1 behaviour for me. This is the URI Protocol option in config.php; default in EE 2 is "auto" but if I set it to "path_info" instead, the rewrites work as they did in EE 1.

3
  • 2
    It's hard to exactly tell what you're trying to accomplish by removing those segments for the URL. Can you add some clarity on why you're doing this?
    – Siebird
    Commented Nov 27, 2012 at 21:47
  • Thank you for commenting. :) I've added some further information which I hope clarifies. It all basically comes down to trying to stay with the established URL structure for my site. Commented Nov 28, 2012 at 0:02
  • That URI Protocol had me pulling my hair for way to long trying to get the old subsite method working. Discovered it by accident, but yeah, 'path_info' seems to restore a number of old EE behaviors. Commented Dec 5, 2012 at 15:02

5 Answers 5

9

You should do this inside ExpressionEngine rather than trying to do it with messy htaccess rules - far more maintainable and guaranteed to work across servers.

I use Freeway which allows you to set up complex routes to map URLs to specific templates, and in your case it would also let you remove the first segment from specific URLs.

2
  • Agree, any solution that allows you to bypass htaccess and stick to pure EE (or + addon) would probably be better.
    – blenddev
    Commented Nov 28, 2012 at 16:29
  • 1
    I'll be giving this a try, thank you. My only concern with an add-on is if it breaks with a future update in case it isn't being actively developed. Commented Nov 29, 2012 at 10:53
3

If I'm understanding you right, you should be able to get it to work with the basic remove index htaccess rule. You said that you want to

avoid creating several single-template template groups

if thats the case, you can just create a search template in your default template group (lets say westero) and as long as there isn't a template group named the same "/search/shirts" should direct to the 'westero/search' template and pass shirts as a segment_2 variable that you could search on.

1
  • Yes, I know it would work for the default group, but it would complicate the maintenance a bit; I've tried to keep it free from anything but the actual index templates. And it would still leave the issue of the Pages. I wouldn't have tried to do it this way if it wasn't for the fact that it actually worked on EE 1 and now it would be awkward to change things around. :) Commented Nov 28, 2012 at 12:30
1

Yet another way to do this would be to disable "Use Strict URLS" in global template prefs and set "Westeros" as your default template group - you can then access any template in that group at /<template-name>: see What does “Enable Strict URLs” really mean? for details and caveats

1
  • Thank you. :) I don't actually have strict URLs enabled, but part of the issue was that using the default template group wasn't really ideal for my purposes (and it wouldn't sort out the issue with the Pages, anyway). I am looking at some of the add-ons suggested. :) Commented Nov 29, 2012 at 10:50
0

I have not used this so can not comment on how suitable it is for your needs. http://devot-ee.com/add-ons/router

1
  • I'll look into both this and Freeway, thank you. :) Commented Nov 29, 2012 at 10:54
0

I'm using this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

# Redirect search results Requests
RewriteRule ^search/results(.*)$ http://www.mysite.com/zoek/resultaat$1 [L,R=301]

# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule> 

I thought this might come in handy in scenario 2 - search. My search didn't work either and i also needed a single search page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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